PHP Logical Operators precedence affects variable assignment results strangely
问题 $var4 = 123; function fn1($p1) { return array('p1' => 1, 'p2' => 2); } if ($var1 = fn1(1) AND $var4 == 123) { print_r($var1); } if ($var2 = fn1(1) && $var4 == 123) { print_r($var2); } if (($var3 = fn1(1)) && $var4 == 123) { print_r($var3); } If you run this simple script it will output strange results, at least for me!! First output from first if expression will result in an array returned from the function & assigned to the $var1 variable, which is what I'm expecting, well? Second output