Originally published on zero2php.dev — part of the Zero to PHP course. View this lesson on the original site.
Single vs double quotes
Single quotes '...' are mostly literal; double quotes "..." can interpolate variables.
Example
<?php
declare(strict_types=1);
$name = 'Ada';
echo 'Hello $name', "\n"; // literal $name
echo "Hello $name", "\n"; // interpolates
Concatenation
Concatenate with .:
$greeting = 'Hello ' . $name . "\n";
Escapes
Escape sequences like "\n" and "\t" work in double-quoted strings; in single quotes, \ and ' are the common escapes.
Exercise
Set $name to Ada, then echo a double-quoted string so the output is exactly Hi Ada (one space after Hi).
From Zero to PHP — PHP foundations: environment, syntax, and values