I have 2 arrays from a results table, Player and Score. Each player can submit multiple scores. I want to end up with two arrays, unique players and their best score. I think it should be easy but I cannot work it out.
<?php
$player = array("Alan", "Bill", "Colin", "Dave", "Bill", "Bill", "Colin", "Colin", "Dave");
$playerLen = count($player);
$score = array(1,2,3,4,5,6,7,8,9);
$scoreLen = count($score);
$uniqPlayerAr = array();
$highScoreAr = array();
$i=0;
for ($i = 0; $i <$playerLen; $i++) {
$highScore=0;
$playerName = $player[$i];
$thisScore = $score[$i];
if($thisScore>$highScore){
$highScore = $thisScore;
}
if(in_array($playerName, $uniqPlayerAr, true)){
array_push($highScoreAr, $highScore);
}else{
array_push($uniqPlayerAr, $playerName);
array_push($highScoreAr, $highScore);
}
}
$uniqPlayerArLen = count($uniqPlayerAr);
echo "<br>there are ".$uniqPlayerArLen." uniq Players and ".$scoreLen." scores<br>";
$i = 0;
for ($i = 0; $i <$uniqPlayerArLen; $i++) {
echo "highScore for ".$uniqPlayerAr[$i]." = ".$highScoreAr[$i]."<br>";
}
?>


SELECTinstead?