The behaviour of the or operator in PHP

前端 未结 4 999
陌清茗
陌清茗 2020-12-05 04:05

I\'m trying to understand the behavior of or operator. Please see the below examples:

$e = false || true;
var_dump($e);

Outpu

4条回答
  •  臣服心动
    2020-12-05 04:38

    $foo or $foo = 5;
    
    Suppose let say $foo=true or $foo=5;
    

    here it will not evaluate after or operator expresion so output will be $foo=1 Now the expression is

    $foo=false or $foo=5;

    Here it will evaluate after or as = higher precedence so $foo as of which of which it will evaluate $foo=5so output will be 5 But when we evaluate $foo=false or true so here it will consider = higher precedence so the output will be $foo=false but whole expression will evaluate as true because false or true becomes false

提交回复
热议问题