Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $data = ["fire", "water", "wind", "fire", "thunder"];
- function deck($data){
- $counts = [];
- foreach($data as $elem){
- if(isset($counts[$elem])){
- $counts[$elem]++;
- }else{
- $counts[$elem]=1;
- }
- }
- $max = 0;
- $result = [];
- foreach($counts as $elem => $count){
- if($count < $max){
- continue;
- }
- if($count > $max){
- $result = [];
- $max = $count;
- }
- $result[] = $elem;
- }
- return $result;
- }
- echo implode(",", deck($data));
Add Comment
Please, Sign In to add comment