0

I have multiple arrays in in this format:

array = array(
    [0] => String
    [1] => String
    [2] => 1234
)

All of these arrays are contained in a single array. Is there any way i could sort each array in the Main array by the Number [2] from Highest to lowest. I have seen things like rsort(), but never got them to work. Thanks.

I just tried this, but it does not work for the last array?

function sortByOrder($a, $b) {
    return $a[1] - $b[1];
}

$array = array(array("sdfdf", "dddfg", 153), array("dd", "dd", 80), array("dd", "ddd", 155));

usort($array, 'sortByOrder');
print_r($array);
Hunter Mitchell
  • 7,063
  • 18
  • 69
  • 116

1 Answers1

1

After further research i figured out that i could use this:

$array = array(array("sdfdf", "dddfg", 153), array("dd", "dd", 80), array("dd", "ddd", 155));

usort($array, function($a, $b) {
    return $a[2] - $b[2];
});

print_r(array_reverse($array));

Then reverse the order of that array.

Hunter Mitchell
  • 7,063
  • 18
  • 69
  • 116