I'll make it rather easy for you, a trick that works particularly well with php and the fact that your array has numerical values to count.
The counting:
$countedStuff = NULL;
foreach($your_array as $a)
$countedStuff[$a] = (isset($countedStuff[$a]))?$countedStuff[$a]+1:1;
PHP doesn't require you create each member [index] of the array - so you only need to create those that match your value. New indices get set to 1; older indices increment.
In php, this can even be done with alphanumeric values as indices.