Null Coalescing
?? returns the left value if it exists and is not null, otherwise the right. ??= assigns only if missing.
Example
$a = null;
echo $a ?? "default", "\n";
$arr = [];
$arr["k"] ??= 5;
echo $arr["k"], "\n";
echo $undefined ?? "none";Result
default 5 none
Exercise
Default value.
$x "none"
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.