-1

Possible Duplicate:
Sort multidimensional Array by Value (2)

array(200) {
  [0]=>
  array(5) {
    ["cat"]=>
    string(6) "Movies"
    ["name"]=>
    string(22) "Life.of.Pi.2012.DVDSCR"
    ["url"]=>
    string(62) "https://thepiratebay.se/torrent/8036528/Life.of.Pi.2012.DVDSCR"
    ["seed"]=>
    string(5) "33981"
    ["leech"]=>
    string(5) "18487"
  }
  [1]=>
  array(5) {
    ["cat"]=>
    string(6) "Movies"
    ["name"]=>
    string(41) "Django Unchained 2012 DVDSCR X264 AAC-P2P"
    ["url"]=>
    string(81) "https://thepiratebay.se/torrent/7990804/Django_Unchained_2012_DVDSCR_X264_AAC-P2P"
    ["seed"]=>
    string(5) "34279"
    ["leech"]=>
    string(5) "12256"
  }
...
}

I have such an array as shown above, and I would like to sort this array by seed indicator. How to achieve this in php?

Community
  • 1
  • 1
Karolis Mazukna
  • 377
  • 1
  • 6
  • 12

2 Answers2

3

You can use usort() like this.

usort($torrentList, function($a, $b) {
    return $a['seed'] - $b['seed'];
});

Where $torrentList is the the array you showed us above. Documentation can be found here.

Austin Brunkhorst
  • 20,704
  • 6
  • 47
  • 61
0
usort($the_array, function($a, $b) {
    return ($a['seed'] - $b['seed']);
});
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156