This code works in PHP 7.x
$array = ['asda' => ['asdasd']];
$var = $array['asda']['asdasd'] ?? "yes!";
echo $var;
If we replace ??
with ?:
as we have in older PHP version, this code will not work, for example:
$array = ['asda' => ['asdasd']];
$var = $array['asda']['asdasd'] ? $array['asda']['asdasd'] : "yes!";
echo $var;
It means, we will get an error like:
Notice</b>: Undefined index: asdasd in <b>[...][...]</b> on line
So, can we use the first example in PHP 7.x without afraid about anything strange/unexpected in behind
? I mean, is it safe to use this instead, for example, array_key_exists
or isset