I have an array that looks like this:
Array ( [0] => Array ( [filters] => Array ( [filter_1] => 1
[filter_2] => 1
[filter_3] => 1
[filter_4] => 1
[filter_5] => 1
[filter_6] => 1 ),
[count] => 2),
[1] => Array ( [filters] => Array ( [filter_1] => 1
[filter_2] => 1
[filter_3] => 1
[filter_4] => 1
[filter_5] => 1
[filter_6] => 1 ),
[count] => 34)
[2] => Array ( [filters] => Array ( [filter_1] => 1
[filter_2] => 1
[filter_3] => 1
[filter_4] => 1
[filter_5] => 1
[filter_6] => 1 ),
[count] => 7)
Is it possible to sort the main array keys by the [count] key in each, descending? So that they are in the following order: 1 -2 -0
You definitely want the usort function. You can define how the sort function determines which is larger or smaller.
If it’s alright that each sub-array (of “filters” and “count”) gets re-indexed, this should work perfectly. By re-indexed, I mean the newly sorted array would start at 0, progress to 1, etc. This is almost always how you want it, unless your original array is associative.
For example: