是否可以在if语句本身之外构建if表达式?我可以在语句之外连接多个条件,然后在另一个if语句中测试它们吗?
例如
$var= '$varCars==5 && varBikes == '.$totalBikes;
if(isset($trucks){
$var= $var.' && varTrucks=='.$totalTrucks';
}
if($var){
run some code
}
这在VBScript中很容易!!
Harj
答案 0 :(得分:0)
这就是你想要的吗?
$intA = 1;
$intB = 2;
// Returns boolean
$bool = ($intA === 1 && $intB === 2);
if($bool) echo "Yes, it is true<br>";
// if / else
$statement = ($intA === 1) ? 2 : 1;
if($statement === 2) echo "Yep, it is true.<br>";
// if / elseif / else
$statement = ($intA === 2) ? 2 : (($intB === 2) ? 2 : 1);
if($statement === 2) echo "Yep, intA is not equal to 2 but intB is, it is true.<br>";
// if / else concatenate in echo
echo "Hello ".(($intA === 2) ? "John" : "Jane")." do you want to grab some coffee?<br>";