I have an array that looks like this:
Array
(
[0] => Array
(
[0] => A
[1] => -1
[2] => -1
)
[1] => Array
(
[0] => B
[1] => 0
[2] => 1
)
[2] => Array
(
[0] => C
[1] => -1
[2] => 0
)
)
My objective is to sort this array by each nested array, meaning that I want to sort the array by the values of [1] in each, then by the values of [2] in each, etc. My current code is below, and I can understand why it doesn't provide the result that I want. Each time the loop passes through, it overrides $csvarray and I get just multiples of the same thing.
I want to put each sorted array into its own array so I can display them in an HTML table later. I've tried setting variables using $i but have had no success.
for ($i = 1; $i < count($csvarray); $i++) {
uasort($csvarray, function($a, $b) {
return $b[$i] <=> $a[$i];
});
echo "<pre>";
print_r($csvarray);
echo "</pre>";
}
User AbraCadaver gave me the correct answer for what I was looking for, with the following:
for ($i = 1; $i < count($csvarray); $i++) {
array_multisort(array_column($csvarray, $i), SORT_DESC,
$csvarray, SORT_DESC);
echo "<pre>";
print_r($csvarray);
echo "</pre>";
}