Forum Moderators: coopster
if (!empty($foo))
$bar = (array) $foo;
elseif (!empty($lorem))
$bar = $lorem; $bar = (array) $foo ? $lorem; $bar = $foo ? $lorem;
settype($bar, 'array'); $bar = (array) ($foo ? $lorem); you should let the PHP optimizer do its work
your short version is not doing the same as the if thenif . Because I guess that both foo and lorem can be empty, then bar, should be undefined.
$bar = (array) ($foo ?? $lorem);
if (empty($bar)) $bar = false;
$bar = ( ( $foo ?? false ) !== false ) ? $foo : ( $lorem ?? false ) ; What do you mean?