3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $input = [ [3, 8, 1, 7], [3, 8, 7, 7], [7, 9, 7, 8], [1, 2, 4, 1] ]; echo "input array: "; print_r($input); $sort_keys = $input[0]; asort($sort_keys); $sorted = array_map(function($row) use ($sort_keys){ foreach ($sort_keys as $key => $value) { $result[] = $row[$key]; } return $result; }, $input); echo "sorted array: "; print_r($sorted);
based on ClZRo
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0rc3
input array: Array ( [0] => Array ( [0] => 3 [1] => 8 [2] => 1 [3] => 7 ) [1] => Array ( [0] => 3 [1] => 8 [2] => 7 [3] => 7 ) [2] => Array ( [0] => 7 [1] => 9 [2] => 7 [3] => 8 ) [3] => Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 1 ) ) sorted array: Array ( [0] => Array ( [0] => 1 [1] => 3 [2] => 7 [3] => 8 ) [1] => Array ( [0] => 7 [1] => 3 [2] => 7 [3] => 8 ) [2] => Array ( [0] => 7 [1] => 7 [2] => 8 [3] => 9 ) [3] => Array ( [0] => 4 [1] => 1 [2] => 1 [3] => 2 ) )