php - Counting the frequency in 100 arrays, want the 6 most frequent numbers to be displayed -
i display 6 frequent numbers out of 100 arrays displayed, far have this:
foreach($lottotickets $i =>$ivalue) { $counts = array_count_values($tickets); arsort($counts); $list = array_keys($counts); var_dump($list); }
but shows frequency seperate arrays, not want.
the below code fetch 6 frequent elements among 100 arrays:
$freqarr = array(); foreach($allarrays $array) { foreach($array $num) { if(isset($freqarr[$num])) { $freqarr[$num] += 1; } else { $freqarr[$num] = 1; } } } arsort($freqarr); $counts = array_slice($freqarr, 0, 5); $list = array_keys($counts); var_dump($list);
Comments
Post a Comment