&& (and)、||(or) 条件语句

当前面条件满足时,就执行后面的代码

//条件为真时,就执行其中的语句

if($a>0){

    $b='This is test';

}

//上面的写法太麻烦,可以这样简写

$a>0 && ($b='This is test');

 

and 或 && ,为真时,执行

1 <?php
2 $val = true;
3 $val and die('ERROR KEY!'); //退出并输出 ERROR KEY!

 

or 或 || ,为假时,执行

1 <?php
2 $val = false;
3 $val or die('ERROR KEY!'); //退出并输出 ERROR KEY!

 

posted on 2019-01-16 00:17  zhuyongzhe  阅读(161)  评论(0编辑  收藏  举报

导航