Rate this script:  I Love it  /   I Hate it

Array group by count


Code


<?php
function ArrayGroupByCount($_array, $sort = false) {
   $count_array = array();

   foreach (array_unique($_array) as $value) {
       $count = 0;

                foreach ($_array as $element) {
                    if ($element == $value)
                        $count++;
                }
       
                $count_array[$value] = $count;
        }
       
        if ( $sort == 'desc' )
                arsort($count_array);
        elseif ( $sort == 'asc' )
                asort($count_array);

        return $count_array;
}
?>
 

 

 
Array group by count scripts | Array group by count snippet | Array group by count example | Array group by count tutorial | Array group by count code