🐘 PHP Beginner

What is string interpolation in PHP?

Answer

PHP supports variable interpolation inside double-quoted strings — variables and expressions are automatically replaced with their values. Simple variable: "Hello, $name!". For array values or object properties, use curly braces: "User: {$user["name"]}" or "Age: {$user->age}". Single-quoted strings do NOT interpolate variables — 'Hello, $name' outputs the literal string with the dollar sign. Using single quotes for strings with no variables is marginally faster and clearly signals no interpolation is expected. The heredoc syntax (<<<EOT) also supports interpolation for multi-line strings, while nowdoc (<<<'EOT') does not.