有没有办法不使用!在PHP中空三次?

shi*_*hin 3 php if-statement

我想发表if声明.如果一个数组$list[0],$list[1]并且$list[2]不是空的,那么我就足够了,这样我就可以做到这些.

if(!empty($list[0]) AND !empty($list[1]) AND !empty($list[2])){
// do something
}else{
// output error and redirect
}
Run Code Online (Sandbox Code Playgroud)

有没有其他方法可以缩短上述if语句?还是足够好?

Mch*_*chl 6

把事情简单化.你可能以看似"更聪明"的方式做到这一点,但事实上它可能只会使代码更不易读.