Using array_multisort() to Sort Multiple Arrays in PHP


Sort multiple arrays or multi-dimensional arrays based on one or more conditions.

Source Code

$volume = [67, 85, 85, 98];
$edition = [2, 1, 3, 2];

array_multisort($volume, SORT_DESC, $edition, SORT_ASC);
print_r($volume); // Outputs: Array ( [0] => 98 [1] => 85 [2] => 85 [3] => 67 )
print_r($edition); // Outputs: Array ( [0] => 2 [1] => 1 [2] => 3 [3] => 2 )
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments