PHP supports several ways to define strings, each with different behavior:
$name = 'Alice';
// Single quotes — literal, no variable interpolation, minimal escaping
echo 'Hello, $name'; // outputs: Hello, $name
// Double quotes — variables and escape sequences are interpolated
echo "Hello, $name"; // outputs: Hello, Alice
echo "Hello, {$name}!"; // curly braces for clarity with complex expressions
echo "Line 1\nLine 2"; // \n is an actual newline in double quotes
// Heredoc — multi-line strings with interpolation, no quote-escaping needed
$text = <<<EOT
Dear $name,
Thank you for signing up.
EOT;
// Nowdoc — like heredoc but no interpolation (like single quotes, multi-line)
$raw = <<<'EOT'
No $interpolation here.
EOT;
Single quotes are marginally faster since PHP doesn't need to scan for variables, so many style guides prefer them for strings with no interpolation. String length: strlen($str). Concatenation: . or .=. Accessing a character by position: $str[0].