how to sort a multidemensional array by an inner key

Here you go.

$playergoop is the array that you provided.

This one sorts by the sub-field ‘rank’, but it does so in an ascending order. If you want a descending order, you can switch the > to <.

function sorter($one, $two) {
    return ($one['rank'] > $two['rank']);
}

usort($playergoop['players'], sorter);

Leave a Comment