Jump to content

Sort multi-dimensional arrays.


unknownsheep

Recommended Posts

Hello. I have an array much like this one.

 

array(3) {
  [0]=>
  array(3) {
    [0]=>
    string(2) "11"
    [1]=>
    string(2) "10"
    [2]=>
    string(3) "abc"
  }
  [1]=>
  array(3) {
    [0]=>
    string(3) "130"
    [1]=>
    string(3) "243"
    [2]=>
    string(3) "foo"
  }
  [2]=>
  array(3) {
    [0]=>
    string(2) "76"
    [1]=>
    string(3) "107"
    [2]=>
    string(6) "qwerty"
  }
}

 

I want to sort it so that the inner array with the highest value in the first key [ 0 ] comes first and so on.. In this case $array[1][0] is the biggest.

Its quite hard to explain but it would result in:

 

array(3) {
  [0]=>
  array(3) {
    [0]=>
    string(3) "130"
    [1]=>
    string(3) "243"
    [2]=>
    string(3) "foo"
  }
  [1]=>
  array(3) {
    [0]=>
    string(2) "76"
    [1]=>
    string(3) "107"
    [2]=>
    string(6) "qwerty"
  }
  [2]=>
  array(3) {
    [0]=>
    string(2) "11"
    [1]=>
    string(2) "10"
    [2]=>
    string(3) "abc"
  }
}

Link to comment
https://forums.phpfreaks.com/topic/90872-sort-multi-dimensional-arrays/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.