2016-03-04 89 views
1

我们知道=的优先级低于!运算符优先于php

我的问题:如果上述语句为真,那么如何执行以下if()条件

function foo() 
{ 
    return false; 
} 


if(!$a=foo()) 
{ 
    echo "Yes, foo() appeared here."; 
} 
+5

运营商不仅拥有优先权,他们也有一个[关联](https://en.wikipedia.org/wiki/Operator_associativity#Right-associativity_of_assignment_operators)和'! '是__right__联想,而'='是__left__联想 –

+0

你有一个错字,如果(!$ a = foo())改为if(!$ a == foo()) – St0iK

+1

不知道我明白这个问题,你的意思是“如何执行以下...”? - 逻辑足够好,if条件是:如果'$ a'不是'true',则输入 – Epodax

回答

7

这是一个任务,而不是一个比较。此外,您还有一个需要进行赋值的函数调用。然后顺序是:

1) Function call returning false; 
2) Assignment of false value to $a; 
3) Negation of $a as !false, i.e., true.