1

I need to sort a multidimensional array, and display the values according to the highest to the lowest. How would I do that?

$array[0][0] = "section1";
$array[0][1] = 3;
$array[1][0] = "section2";
$array[1][1] = 1;
$array[2][0] = "section3";
$array[2][1] = 2;

echo "<pre>";
print_r($array);
echo "</pre>";

Result:

section1
3
section2
1
section3
2

Need Result:

section1
3
section3
2
section2
1
frosty
  • 2,559
  • 8
  • 37
  • 73

1 Answers1

1

See usort

function cmp($a, $b) {
        return $b[1] - $a[1];
}
usort($array, "cmp");
Sam Segers
  • 1,951
  • 2
  • 22
  • 28