while ($i = 'AAA' && $j = 'BBB') { var_dump($i, $j); sleep(3);}
输出结果bool(true)string(3) "BBB"
-------------------------------------------------------------在写一个后台监听程序的时候使用了while循环,于是纠结了一下`while`中的条件表达式
For the above code I expected output AAA BBB But why is it true BBB
Look at this piece of code.
while($ret = 100) { var_dump($ret) // output:100}
In this case, the conditional expression in parentheses $ret=100 is how the result is true or is false . I'm thinking of 100 assigning the value to the variable first $ret , and then the $ret boolean value to the result.
I hope you will help us with doubts. Thank you, sir.
Reply content:
while ($i = 'AAA' && $j = 'BBB') { var_dump($i, $j); sleep(3);}
输出结果bool(true)string(3) "BBB"
-------------------------------------------------------------在写一个后台监听程序的时候使用了while循环,于是纠结了一下`while`中的条件表达式
For the above code I expected output AAA BBB But why is it true BBB
Look at this piece of code.
while($ret = 100) { var_dump($ret) // output:100}
In this case, the conditional expression in parentheses $ret=100 is how the result is true or is false . I'm thinking of 100 assigning the value to the variable first $ret , and then the $ret boolean value to the result.
I hope you will help us with doubts. Thank you, sir.
if (($i = 'AAA') && ($j = 'BBB')) { var_dump($i, $j);}
Note the && priority level
Operator logic problem, price brackets are on the square.
while (($i = 'AAA') && ( $j = 'BBB')) { var_dump($i, $j);// true bbbbb sleep(3);}
The comma operator causes output BBB, v=1,2 at this point, V is 2
2. Dead Loop,. Convert to Boolea can ret = ret && true