I have the following array:
$string = ('10','21','22','30','41','42','43');
I need to count the number of values which start with 1, 2, 3, 4
to get this... 1: result 1 2: result 2 3: result 1 4: result 3
huh?
what does result1 mean? and i assume the 1 2 3 4 is that you want them to be in order right(lowest to highest)?
here is one way of doing it:
$result=array(); while(list($k,$v)=each($string)) { $result[substr($v,0,1)]++; } print_r($result);
Thanks! 🙂