This method will only loop each value once compared to other methods posted here.
Instead of looping the full array I get unique values and count them with array_keys and count.
$arrayName = array(1,2,1,3,4,3,2,5);
$values = array_unique($arrayName);
Foreach($values as $val){
$count[$val] = count(array_keys($arrayName, $val));
}
Var_dump($count);
In your example I think my method may actually be slower than looping the full array, but if this was a large array there may be a benefit of not looping the full array.
4
solved How do I make an array without using array_count_values()?