What is the difference between single and double quotation marks in PHP string formatting?
Single quotation marks in PHP are used to create string literals where variables and escape sequences are not interpreted. Double quotation marks, on the other hand, allow for variable interpolation and interpretation of escape sequences within the string. When using double quotation marks, PHP will parse the string and replace any variables or escape sequences with their values. To avoid unexpected behavior, it is important to choose the appropriate quotation marks based on the desired functionality.
// Using single quotation marks to create a string literal
$name = 'John';
echo 'Hello, $name'; // Output: Hello, $name
// Using double quotation marks for variable interpolation
$name = 'John';
echo "Hello, $name"; // Output: Hello, John