I'm trying to rank a group of scores. So I've taken the input from a users form and sorted them from largest to smallest in a multidimensional array, so then that I can search the array for the user and retrieve the index to get its "rank" however I appear to be doing something totally wrong! any help on where I'm going wrong would be greatly appreciated, or if there is a better way entirely!
Thank you
Thank you
PHP:
if(isset($_POST['submit']))
{
$size = $num_rows;
$p = 0;
$myarray = array();
while($p < $size)
{
$myarray[] = array("user" => $user[$p], "data" => $scanrate[$p]);
$p++;
}
$sort = array();
foreach($myarray as $k=>$v)
{
$sort['data'][$k] = $v['data'];
}
array_multisort($sort['data'], SORT_DESC, $myarray);
for($i=0;$i<$num_rows;$i++)
{
$key = array_search($i, array_column($myarray, 'user'));
if(!$key)
{
$key = $num_rows;
}
//this is stored into my database
echo "<br>User ".$user[$i]." scan rate ".$scanrate[$i]." rank ".$key;
}
}