我有foreach
,其中包括候选人名单。我正在尝试计算foreach中的百分比然后输出结果。我不知道问题,我希望程序计算第一个 if语句(talent),然后转到下一个 if语句(距离),然后继续计算。 echo
将显示百分比的整体计算。请帮忙。提前致谢
$counter = 0;
$status = array();
foreach($candidate as $c){
$queryResult = mysql_query("SELECT * FROM candidates WHERE id = '$c'");
$row = mysql_fetch_assoc($queryResult);
if($talent == "good"){
$status[$counter] = + 0.10;
}else if($talent == "better"){
$status[$counter] = + 0.05;
}
if($distance == "1200m"){
$status[$counter] = + 0.10;
}else if($distance == "1400m"){
$status[$counter] = + 0.05;
}
echo $status[$counter] * 100 . "%<br>";
$counter ++;
}//foreach end
答案 0 :(得分:0)
如何用=+
更改+=
,或许这就是你想要的......? (例如,$status[$counter] += 0.10;
)
并尝试在foreach
循环之前初始化..
$array = array_fill(0,$number_of_candidates, 0);