I have an array of mysql records in $allrecords variable.
There are multiple keys for each record and one of the key is called type.
Some of the variable has the same type.
E.g. it looks like this:
Seat
Mercedes
BMW
BMW
Mercedes
Audi
Mercedes
Fiat
Mercedes
Audi
Fiat
Mercedes
The array is unordered now (just grabbed from database) and now I need to order the array items from the most occurance one to the least.
E.g. like this
Mercedes (5)
Audi (3)
BMW (2)
Fiat (2)
Seat (1)
I do not need the numbers (that I get using another foreach loop), so I need it just like this:
Mercedes
Audi
BMW
Fiat
Seat
How to do such this in PHP? Is it possible? I need to group the items based on the type and then order them from the most to the least occurance.
Thanks in advance.
EDIT:
My array look like this:
Array
(
[0] => stdClass Object
(
[id] => 125
[user_id] => 29
[show] => 1
[state] => 1
[type] => 23
[subcat_id] => 11
[category_id] => 2
[name] => SLK 350
)
)
1 Answer