Reputation: 68440
let's say I have something like this:
if(1 == 0 && do_stuff()) {
...
}
Obviously 1 is not 0, so there's no point to check the other condition. So does PHP ever run do_stuff()
?
Upvotes: 23
Views: 4496
Reputation: 3634
If first condition is false then php never run the second condition in && operator
Upvotes: 4
Reputation: 54445
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.
Upvotes: 49