开发者

PHP - if (condition) execution

开发者 https://www.devze.com 2023-01-28 12:32 出处:网络
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_st

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号