Guest User

Untitled

a guest
Jun 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. <?php
  2.  
  3. $data = ["fire", "water", "wind", "fire", "thunder"];
  4.  
  5. function deck($data){
  6. $counts = [];
  7. foreach($data as $elem){
  8. if(isset($counts[$elem])){
  9. $counts[$elem]++;
  10. }else{
  11. $counts[$elem]=1;
  12. }
  13. }
  14.  
  15. $max = 0;
  16. $result = [];
  17.  
  18. foreach($counts as $elem => $count){
  19. if($count < $max){
  20. continue;
  21. }
  22. if($count > $max){
  23. $result = [];
  24. $max = $count;
  25. }
  26. $result[] = $elem;
  27. }
  28. return $result;
  29. }
  30.  
  31. echo implode(",", deck($data));
Add Comment
Please, Sign In to add comment