Skip to content
Advertisement

Sorting a multi-dimensional array based on a consistent array key in PHP

I am trying to sort a multidimensional array value based on a consistent key. My array looks something similar to this and the key I want to sort values in order by is discipline_one.

JavaScript

Going off the id key in the above example, my expected output would be in the order:

JavaScript

Previously, to query based on score I used:

JavaScript

However, if I add an additional array_column on this for the discipline_one consistent key then I get:

JavaScript

array_multisort(): Array sizes are inconsistent

The third argument expects the same array which in this case is not possible. Does any one know a way I can achieve this?

Advertisement

Answer

Why not using simple usort?

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement