- array_map: documentation ( source)
- print_r: documentation ( source)
- asort: documentation ( source)
<?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);