如何将if语句放在if语句中?现在是这样的,
<?php
if($var1===$var2)
{
if($condition1 > 0)
{
*lots of code here*
}
}
else
{
*lots of code here again*
}
}
?>这意味着如果$condition1与$var2不匹配,我希望$var1大于0。但是现在我复制了“大量的代码部分”,所以我只想;
if($var1!=$var2){ -apply if statement- }
*lots of code here*
if($var1!=$var2){ -close if statement- } 但是怎么做呢?
发布于 2011-06-26 18:14:11
<?php
$a = ($var1 === $var2);
$b = ($condition1 > 0);
if (!$a || $b)
{
*lots of code here*
}
?>发布于 2011-06-26 18:13:57
您有正确的方法来组合两个if语句。但是,无论是当var1等于var2还是当condition1大于0时,您都希望运行大量代码。你可以这样写:
<?php
if ($var1===$var2 || $condition1 > 0)
{
*lots of code here again*
}
?>||运算符的意思是'or‘。
发布于 2011-06-26 18:15:19
也许我不明白,但我会这样做:
if($var1 === $var2 || $condition1>0){
//lots of code here
}else{
}编辑-也许你不想这样-如果var1等于var 2或者如果var1不等于var2和condition1>0,它会写很多代码
if($var1 === $var2 || ($var1 !== $var2 && $condition1>0)){
//lots of code here
}else{
}https://stackoverflow.com/questions/6483323
复制相似问题