这段代码给出了4个4,我只想要一个4 ..任何人都可以识别问题吗?
$value1 = "0";
$entries = array($var1_1a>$var1_1b, $var1_2a>$var1_2b, $var1_3a>$var1_3b,
$var3_1a>$var3_1b, $var3_2a>$var3_2b, $var3_3a>$var3_3b);
if (count($entries) == 0)
echo "0";
else foreach($entries as $entry)
{
if($entry > $value1)
{
echo array_sum($entries);
}
}
答案 0 :(得分:0)
$value1 = "0";
$entries = array($var1_1a>$var1_1b, $var1_2a>$var1_2b, $var1_3a>$var1_3b,
$var3_1a>$var3_1b, $var3_2a>$var3_2b, $var3_3a>$var3_3b);
if (count($entries) == 0)
echo "0";
else foreach($entries as $entry)
{
if($entry > $value1)
{
echo array_sum($entries);
break; //I think it will checking condition repeatedly
}
}
答案 1 :(得分:0)
为什么你甚至有一个foreach循环? echo array_sum($entries);
与您循环的值无关。
这应该足够了:
$entries = array($var1_1a>$var1_1b, $var1_2a>$var1_2b, $var1_3a>$var1_3b,
$var3_1a>$var3_1b, $var3_2a>$var3_2b, $var3_3a>$var3_3b);
echo array_sum($entries);