Concept Flow - String interpolation in double quotes
Start
Define variable
Use variable inside " "
PHP replaces variable with value
Output final string
End
PHP replaces variables inside double quotes with their values before outputting the string.
<?php $name = "Alice"; echo "Hello, $name!"; ?>
| Step | Code Line | Action | Variable Values | Output |
|---|---|---|---|---|
| 1 | $name = "Alice"; | Assign string 'Alice' to $name | $name = 'Alice' | |
| 2 | echo "Hello, $name!"; | Replace $name with 'Alice' inside string | $name = 'Alice' | Hello, Alice! |
| 3 | End | Script ends | $name = 'Alice' |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| $name | undefined | 'Alice' | 'Alice' | 'Alice' |
PHP String Interpolation in Double Quotes: - Variables inside " " are replaced with their values. - Use $variable syntax inside double quotes. - Single quotes ' ' do NOT interpolate variables. - Useful for embedding variables directly in strings. - Example: echo "Hello, $name!" outputs Hello, Alice!