3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [ [6,3,9], [9,1,6], [4,7,9] ]; 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);
Output for 5.5.0 - 5.5.37, 5.6.0 - 5.6.23, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
input array: Array ( [0] => Array ( [0] => 6 [1] => 3 [2] => 9 ) [1] => Array ( [0] => 9 [1] => 1 [2] => 6 ) [2] => Array ( [0] => 4 [1] => 7 [2] => 9 ) ) sorted array: Array ( [0] => Array ( [0] => 3 [1] => 6 [2] => 9 ) [1] => Array ( [0] => 1 [1] => 9 [2] => 6 ) [2] => Array ( [0] => 7 [1] => 4 [2] => 9 ) )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 input array: Array ( [0] => Array ( [0] => 6 [1] => 3 [2] => 9 ) [1] => Array ( [0] => 9 [1] => 1 [2] => 6 ) [2] => Array ( [0] => 4 [1] => 7 [2] => 9 ) ) sorted array: Array ( [0] => Array ( [0] => 3 [1] => 6 [2] => 9 ) [1] => Array ( [0] => 1 [1] => 9 [2] => 6 ) [2] => Array ( [0] => 7 [1] => 4 [2] => 9 ) )

preferences:
201.73 ms | 403 KiB | 247 Q