Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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>";
- }
- ?>
Add Comment
Please, Sign In to add comment