-1

If I have this array:

array(
    [0] => array(5, "hi"),
    [1] => array(2, "hello"),
    [2] => array(9, "test")
)

How can I sort this array by [n][0]?
The end result should to be like this:

array(
    [0] => array(9, "test")
    [1] => array(5, "hi"),
    [2] => array(2, "hello"),
)
1

1 Answer 1

0

You can use a custom comparison function:

function multi_sort($a, $b)
{
    return $a[0] < $b[0];
}

usort($array, 'multi_sort');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.