I have a question similar to this one: PHP Sort Array By SubArray Value however it is a bit different since I want to find/search for the highest of many subarray values and sort the "main" array after that. Below is the array structure I have, with groupings that contain a number of subitems where each subitem has a score.
Array
(
[grouping1] => Array
(
[0] => Array
(
[_score] => 8.2
[_source] => Array
(
[name] => Subitem 1111,
[ID => 999
)
)
)
[grouping2] => Array
(
[0] => Array
(
[_score] => 8.546042
[_source] => Array
(
[name] => Subitem2222,
[ID] => 987654
)
)
)
[grouping3] => Array
(
[0] => Array
(
[_score] => 10.163501
[_source] => Array
(
[name] => Subitem3333
[ID] => 12345
)
)
[1] => Array
(
[_score] => 8.55
[_source] => Array
(
[name] => Subitem4444,
[ID] => 67890
)
)
[2] => Array
(
[_score] => 9.55
[_source] => Array
(
[name] => Subitem5555
[ID] => 65421
)
)
)
)
I would like to
- Check the highest score amongst subitems for each grouping
- Sort groupings after highest available subitem score
The expected output is the containing array to have this order
- [0] grouping3 since its highest subarray score is 10.163501
- [1] grouping2 since its highest subarray score is 8.546042
- [2] grouping1 since its highest subarray score is 8.2