Info
Open the page on your phone

What is the difference between single and double quotes?

Double Quotes:

  • In double quotes, PHP allows the use of escape sequences (such as `\n`, `\r`, `\"`, `\$`, etc.) and variable interpolation, where variable values can be directly inserted into the string.
  • For example:
  •                         
    $name = "John";
    echo "Hello, $name!";
    // Output: Hello, John!
                            
                        

    Single Quotes:

  • In single quotes, escape sequences are not interpreted, and variables inside the string are treated literally. Variables in single quotes are not expanded.
  • For example:
  •                         
    $name = "John";
    echo 'Hello, $name!';
    // Output: Hello, $name!
                            
                        

    Wrapping a string in double quotes can be convenient when you need to insert variable values or use escape sequences. However, in some cases, using single quotes may be more efficient since PHP does not have to search for and interpret variables or escape sequences.

    The choice between single and double quotes depends on the specific use case and your requirements.