When would a PHP variable assignment return false?
In this answer the following code is suggested
while (($lastPos = strpos($html, $needle, $lastPos))!== false) {
$positions[] = $lastPos;
$lastPos = $lastPos + strlen($needle);
}
... the while loop will end when the assignment...
$lastPos = strpos($html, $needle, $lastPos)
...returns false.
When would this assignment return false and why?
Thanks
A variable assignment returns the value you assigned to the variable. So when the strpos
call returns false
(when the $needle
isn't found), so will the assignment, and the loop will terminate.