-1

I have a multi array that look like that:

Array (
    [0] => Array(
        [0] = Number;
        ),
    [1] => Array(
        [0] = Number;
        )
 )

And I want to sort it by the "Number" organ For exmaple if I have:

Array (
    [0] => Array(
        [0] = 2;
        ),
    [1] => Array(
        [0] = 1;
        )
 )

I want to get:

Array (
    [0] => Array(
        [0] = 1;
        ),
    [1] => Array(
        [0] = 2;
        )
 )

I have more content in this arrays, I just wrote what need to be sort

How can I do that?

Kaki Baleven
  • 355
  • 3
  • 7
  • 19
  • 1
    Possible duplicate of [Sort Multi-dimensional Array by Value](http://stackoverflow.com/questions/2699086/sort-multi-dimensional-array-by-value) – Tanuel Mategi Oct 27 '15 at 14:38

1 Answers1

1

try:

Before PHP 5.3

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

usort($array, "cmp");

Updated for PHP 5.3

usort($myArray, function($a, $b) {
    if ($a[0] == $b[0]) {
        return 0;
    }
    return ($a[0] < $b[0]) ? -1 : 1;
});
Peter Kota
  • 8,048
  • 5
  • 25
  • 51