如何在PHP中使用多个条件执行if条件?
问题描述:
我有4个变量。如何在PHP中使用多个条件执行if条件?
我该怎么做?
$x1='on';
$x2='';
$x3='';
$x4='';
if $x1=='on' and $x2 is empty and $x3 is empty and $x4 is empty , do this else do that ?
答
像这样:
if($x =='on' && $x2 =="" && $x3 == "" && $x4 == ""){
}else{
}
以备将来参考PHP手册和这里的链接表现运营商: http://php.net/manual/en/language.operators.logical.php
答
或者,您可以使用空命令,就像这样:
if($x =='on' && empty($x2) && empty($x3) && empty($x4)){
}
else{
}
+1
你[不应该使用'empty'作为应该存在的变量](http://kunststube.net/isset);改用'!$ x2'。 – deceze
http://php.net/manual/zh/language.operators.logical.php –
W欢迎来到Stack Overflow。询问代码的问题必须证明对所解决问题的最小理解。包括尝试解决方案,为什么他们没有工作,以及预期的结果。 – dparoli