1

I'm really sorry if this has been answered before, but here is my problem
I have this:

 array (size=256)
      0 =>
            array (size=2)<br>
                0 => string 'name_a'
                1 => string '2175'
      1 =>
            array (size=2)
                0 => string 'name_d'
                1 => string '1'
      2 =><
            array (size=2)
                0 => string 'name_c'
                1 => string '715'
      3 =>
            array (size=2)
                0 => string 'name_b'
                1 => string '5'

And I want to be able to sort it by the number from most to least or/and name and if I add more info for each name such as time value. Its a huge array(over 400 I think) and I need to display it one by one, from top to bottom. If anyone have any ideas, I'd love to hear them!

1 Answers1

0

Use usort like so:

function myComp($a, $b) {
    if($a[1] == $b[1]) {
        return 0;
    }

    return ($a[1] > $b[1]) ? -1 : 1;
}

usort($myArray, 'myComp');
Jon
  • 4,746
  • 2
  • 24
  • 37