This table consist of 3 column : key-name of product, total value, and rank. These ranks is sorted arsort based on the total value. How to echo only the name of product in the first row that has the biggest total value? How to access the key of the first row that consist of biggest value?
Here is the code of table of rank
<table class="table table-bordered table-striped table-hover">
<tr>
<th></th>
<th>Total</th>
<th>Rank</th>
</tr>
<?php
$rank = get_rank($pref);
foreach($rank as $key => $value){
echo"<tr>";
echo"<th>$key - $PRODUK[$key]</th>";
echo "<td class='text-primary'>".round($pref[$key], 3)."</td>";
echo "<td class='text-primary'>".$rank[$key]."</td>";
echo "</tr>";
$no++;
}
?>
</table>
$key is the key and $PRODUK[key] is the name of the product. And their total value is $pref.
And here is the code for function of get rank
function get_rank($array){
$pref= $array;
arsort($pref);
$no=1;
$new = array();
foreach($pref as $key => $value){
$new[$key] = $no++;
}
return $new;
}