I'm tracking how many words appear in the description of my products and created a multidimensional array that is keeping track but I need to sort them by the most found keywords to the lowest. I have this array and I want to be able to sort it by the "count" key:
Array
(
[KOM1-K182924DA] => Array
(
[count] => 1
[words] => Array
(
[4] => cotton
)
)
[PVH1-U2666001] => Array
(
[count] => 2
[words] => Array
(
[2] => cotton
[5] => briefs
)
)
[GEO2-K2345TF] => Array
(
[count] => 1
[words] => Array
(
[4] => red
)
)
[KOM1-K182871HK] => Array
(
[count] => 3
[words] => Array
(
[4] => cotton
[5] => nylon
[6] => blue
)
)
)
So the result would look like this:
Array
(
[KOM1-K182871HK] => Array
(
[count] => 3
[words] => Array
(
[4] => cotton
[5] => nylon
[6] => blue
)
)
[PVH1-U2666001] => Array
(
[count] => 2
[words] => Array
(
[2] => cotton
[5] => briefs
)
)
[KOM1-K182924DA] => Array
(
[count] => 1
[words] => Array
(
[4] => cotton
)
)
[GEO2-K2345TF] => Array
(
[count] => 1
[words] => Array
(
[4] => red
)
)
)
How can I do this? I've tried multiple solutions that I found on stackoverflow but none of them have worked for me. I've tried the solution on here Sort Multi-dimensional Array by Value. I'm using PHP 5.6 so I tried this:
usort($myArray, function($a, $b) {
return $a['order'] - $b['order'];
});
But it's not returning an array, instead it returns the "sku" and a digit.