Reputation: 620
If I have a matrix
[3,1,2,4]
[a,b,c,d]
And I need sort first row with usort key. But when I want reorder first array how do column moves at well
So output will be like this in this case described top
[1,2,3,4]
[b,c,a,d]
Upvotes: 0
Views: 245
Reputation: 15131
You can use array_multisort:
$x = [[3,1,2,4],['a','b','c','d']];
array_multisort($x[0], $x[1]);
var_dump($x);
Output:
array(2) { [0]=> array(4) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) } [1]=> array(4) { [0]=> string(1) "b" [1]=> string(1) "c" [2]=> string(1) "a" [3]=> string(1) "d" } }
Upvotes: 4