If you want $x
to be a boolean indicating the truthiness of $y || $z
(i.e. if either $y
or $z
is truthy. Then what you posted: $x = $y || $z
will work.
If you want $x to have the same value as the first non false variable you could do a ternary:
$x = $y ? $y : $z;
4
solved PHP Variable definition/declaration with alternative values using “||” “OR” [closed]