php - How to understand this judgment statement without if
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-16 13:12:52
0
5
370
$data ['ToUserName'] == 'gh_3c884a361561' || $this->init_follow ( $data );
曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(5)
phpcn_u1582

$data ['ToUserName'] == 'gh_3c884a361561' is true, take $data ['ToUserName'] = 'gh_3c884a361561' as the result, note the "=", and then discard $this->init_follow ( $data )

$data ['ToUserName'] == 'gh_3c884a361561' is false, discard $data ['ToUserName']== 'gh_3c884a361561', and then judge $this->init_follow ( $data ), if this is true, then Get the result returned by the init_follow() function

仅有的幸福
if($data ['ToUserName'] != 'gh_3c884a361561') {
    $this->init_follow ( $data );
}
伊谢尔伦

||具有短路性。||If the previous statement is true, then the following statement will not be executed.

过去多啦不再A梦

Short circuit AND and logical AND

滿天的星座

Simplified writing method, compared to traditional if, only one line of code is needed

//传统if写法:
if($data ['ToUserName'] != 'gh_3c884a361561') {
    $this->init_follow($data);
}

//推荐使用AND和OR来代替&&和||,AND和OR优先级更低,避免出现优先级问题
$data['ToUserName'] == 'gh_3c884a361561' OR $this->init_follow($data);

//比如一个优先级导致的问题
$result = true && false;//$result为false
$result = true AND false;//$result为true
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template