0

How do I order an array by key, this is example:

array(3){
    [3] => array(),
    [2] => array(),
    [1] => array()
}

What I need is:

array(3){
    [1] => array(),
    [2] => array(),
    [3] => array()
}
3
  • I didn't understand the question. Can you please elaborate on your example? Commented Nov 28, 2011 at 11:03
  • php.net/manual/en/array.sorting.php Commented Nov 28, 2011 at 11:03
  • 1
    Please fix the type of the last element key, which should be 3 (I guess?) Commented Nov 28, 2011 at 11:04

3 Answers 3

2

ksort

Sorts an array by key, maintaining key to data correlations. This is useful mainly for associative arrays.

Sign up to request clarification or add additional context in comments.

Comments

1

Your what I need doesn't make sense, do you really want to kick out [3] ? Other than that, to answer your actual question, to sort arrays by key, just use phps ksort

Comments

0

What you want is ksort().

Comments

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.