<?php $avg = ($sumc)/($data['total']); echo number_format((float)$avg, 2, ',', ''); ?>
<?php
$array = array($avg); // useless
$i=1;
foreach($array as $key=>$value) // also useless, you never use these variables, and since $array contains only one entry, there is no need to foreach it
{
$max = max($array);
echo "
".$max." rank is ". $i."
";
$keys = array_search($max, $array);
unset($array[$keys]);
if(sizeof($array) >0)
if(!in_array($max,$array))
$i++;
}
Let's clean that up :
<?php $avg = ($sumc)/($data['total']); echo number_format((float)$avg, 2, ',', ''); ?>
<?php
$max = $avg; // That's actually what you were doing. Cleaning the code makes it obvious, that's all
echo "
".$max." rank is ". $i."
";
$keys = array_search($max, $array);
unset($array[$keys]);
if(sizeof($array) >0)
if(!in_array($max,$array))
$i++;
}
The code still has errors, but the more we correct, the more its design flaws appear, and the less it's therefore correctable.
You should, in my opinion, look at that code, figure a way to put all the values you want to have in $array in it so that then you can compute the datas you need.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…