Search code examples
phparrayssortingarray-multisort

Synchronously sort values in two particular rows of a 2d array according to the first nominated row


How do I sort both rows in this array by the nums values?

[
    'nums' => [34, 12, 13],
    'players' => ['Mike', 'Bob', 'Mary']
]

Desired result:

[
    'nums' => [12, 13, 34],
    'players' => ['Bob', 'Mary', 'Mike']
]

Solution

  • array_multisort($x['nums'],$x['players']);