-3

I have tried this problem how do you sort this array using the value that is elements in [1]. I would also appreciate if someone demonstrate how print each key and it's value of this array

Array
(
 [0] => Array
    (
        [0] => 9
        [1] => 0
    )

 [1] => Array
    (
        [0] => 10
        [1] => 290
    )

[2] => Array
    (
        [0] => 12
        [1] => 852
    )

[3] => Array
    (
        [0] => 13
        [1] => 9
    )

[4] => Array
    (
        [0] => 14
        [1] => 896
    )
)

please help

Kamotho
  • 317
  • 1
  • 15

1 Answers1

0

You could use uasort

function cmp($a, $b) {
    if ($a[1] == $b[1]) {
        return 0;
    }
    return ($a[1] < $b[1]) ? -1 : 1;
}
uasort($array, 'cmp');

To print each key, value... just iterate over it with a foreach

Victor Henriquez
  • 1,399
  • 15
  • 26