我试图获得一组中最低值的1个结果。所以我有一组数字(平均值)我只需要显示最低的一组:
Node(T value):
nodeValue(value),
leftSon(),
rightSon(),
isEmpty(false) {
}
我一直在尝试使用php min()函数无效!
我的结果通常会像2,2.75,3,3.35等。所以我只需要显示最低的设置。所以像上面那样2。
答案 0 :(得分:3)
您可以将所有值添加到数组中,并使用数组函数来确定获胜者
if ($danresult->num_rows > 0) {
while($row = $danresult->fetch_assoc()) {
$scores=array(
$row["score_1"],
$row["score_2"],
$row["score_3"],
$row["score_4"],
$row["score_5"],
$row["score_6"],
$row["score_7"],
$row["score_8"]
);
$sum= array_sum ($scores);
$totalAverage = $sum / count($scores);
$min=min($scores);
$winner=array_search($min, $scores);
}
}
答案 1 :(得分:1)
试试这个,你需要关闭foreach ...然后从数组中获得最低值
if ($danresult->num_rows > 0) {
while($row = $danresult->fetch_assoc()) {
$score1 = $row["score_1"];
$score2 = $row["score_2"];
$score3 = $row["score_3"];
$score4 = $row["score_4"];
$score5 = $row["score_5"];
$score6 = $row["score_6"];
$score7 = $row["score_7"];
$score8 = $row["score_8"];
$sum = $score1 + $score2 + $score3 + $score4 + $score5 + $score6 + $score7 + $score8;
$totalAverage = $sum / 8;
$totalAverages[] = $totalAverage;
}
$index = min($totalAverages);
echo $index . '<br>';
}