I have a PHP array and I have dumped it below using Zend_Debug:
$ids = array(13) {
[0] => string(1) "7"
[1] => string(1) "8"
[2] => string(1) "2"
[3] => string(1) "7"
[4] => string(1) "8"
[5] => string(1) "4"
[6] => string(1) "7"
[7] => string(1) "3"
[8] => string(1) "7"
[9] => string(1) "8"
[10] => string(1) "3"
[11] => string(1) "7"
[12] => string(1) "4"
}
I am trying to get how many times each number occurs in the array and output it into an array.
I have tried using array_count_values($ids) but it outputs in the order of most occurred but I cant get the Total times the numbers occur. It gives me the below output:
array(5) {
[7] => int(5)
[8] => int(3)
[2] => int(1)
[4] => int(2)
[3] => int(2)
}
I can see from the above array 7 occurs 5 times but I can access it when I loop through the array!
Any thoughts?
Cheers
J.
You can access the data you want like this:
Output:
Demo