Guest User

Untitled

a guest
Dec 11th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. <?php
  2. $player = array("Alan", "Bill", "Colin", "Dave", "Bill", "Bill", "Colin", "Colin", "Dave");
  3. $playerLen = count($player);
  4. $score = array(1,2,3,4,5,6,7,8,9);
  5. $scoreLen = count($score);
  6. $uniqPlayerAr = array();
  7. $highScoreAr = array();
  8. $i=0;
  9. for ($i = 0; $i <$playerLen; $i++) {
  10. $highScore=0;
  11. $playerName = $player[$i];
  12. $thisScore = $score[$i];
  13. if($thisScore>$highScore){
  14. $highScore = $thisScore;
  15. }
  16. if(in_array($playerName, $uniqPlayerAr, true)){
  17. array_push($highScoreAr, $highScore);
  18. }else{
  19. array_push($uniqPlayerAr, $playerName);
  20. array_push($highScoreAr, $highScore);
  21. }
  22. }
  23. $uniqPlayerArLen = count($uniqPlayerAr);
  24. echo "<br>there are ".$uniqPlayerArLen." uniq Players and ".$scoreLen." scores<br>";
  25. $i = 0;
  26. for ($i = 0; $i <$uniqPlayerArLen; $i++) {
  27. echo "highScore for ".$uniqPlayerAr[$i]." = ".$highScoreAr[$i]."<br>";
  28. }
  29. ?>
Add Comment
Please, Sign In to add comment