3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = 1; $b = 2; $c = 0; $d = $e = $f = -1; if ( $d = $c && $e = $b && $f = $a ) { echo "yes"; } var_dump($d, $e, $f); // Why isn't this a parse error?? It doesn't do: // $d = ($c && $e) = ($b && $f) = $a // (because that is a parse error on its own) // So what does it do?? echo "\n\n"; $d = $e = $f = -1; if ( $d = $c and $e = $b and $f = $a ) { echo "yes"; } var_dump($d, $e, $f); // ($d = $c) && ($e = $b) && ($f = $a) so only $d=$c is executed, bc $c is falsy echo "\n\n"; $d = $e = $f = -1; if ( $d = $a and $e = $b and $f = $c ) { echo "yes"; } var_dump($d, $e, $f); // ($d = $a) && ($e = $b) && ($f = $c) and all 3 are executed, bc first 2 are truthy

preferences:
25.28 ms | 404 KiB | 5 Q