0
Why output = 2
<?php $b = 0; $c =1; function get($x) { return $x; } if($a=get($b)) { echo 1; } if($a=get($c)) { echo 2; }
2 Réponses
+ 4
if($a=get($b))
This evaluates to false so the code is not run. $b equals zero and $a is set to zero via the get function, then its value is checked for the if statement. Zero is equivalent to false.
Likewise,
if($a=get($c))
evaluates to true. $c equals 1. $a is set to 1 via the get function and is then checked for the if statement. 1 is equivalent to true, so the code in the if statement is run outputting 2.
0
yeap,,but first if statement have also echo