PHP - if (condition) execution
let's say I have something like this:
if(1 == 0 && do_stuff()) {
...
}
Obvio开发者_Python百科usly 1 is not 0, so there's no point to check the other condition. So does PHP ever run do_stuff()
?
No - PHP uses lazy evaluation (sometimes called short-circuit evaluation), so if the first condition in a logical AND is false, it won't attempt to evaluate any of the other conditions.
Likewise, if you were doing an OR and the first condition was true it wouldn't evaluate the second.
If first condition is false then php never run the second condition in && operator
NO, it'll not execute do_stuff()
in this condition.
精彩评论