I have seen a lot of code online that has a function assigning a value to a variable inside the boolean condition of a while loop:
while ($var = testfunction($param1, $param2))
{
echo "hello world!<br>";
}
($var = testfunction($param1, $param2))
while
testfunction()
TRUE
while
$var
$var
while
$var
==0
!=0
The whole expression is being executed, and its value converted to a boolean.
($var = testfunction($param1, $param2))
First off, testfunction(...)
will be called, and afterwards the assignment will take place. According to the manual:
The value of an assignment expression is the value assigned.
so whatever has been returned and assigned to $var
will be converted to a boolean and evaluated by the WHILE
loop. If if the value assigned is null, [], 0, etc, code block from the while loop will not be executed. Otherwise it will be executed.