1

I'm trying to use PHP's ksort to sort this array:

Array(
    [district_name] => District name
    [email] => [email protected]
    [name] => Name of item
    [number] => 191
    [phone] => +41234568789
    [{attr}id] => 2
    [questions] => Array(...)
)

But the key that contains {attr}... does not get sorted, it stays at the same place while the other keys gets sorted. What is the best method to sort this array?

2
  • 1
    On which place you want {attr}id to be ? Commented Apr 11, 2011 at 9:25
  • It gets sorted here to end of the array. Commented Apr 11, 2011 at 9:29

1 Answer 1

3

I can't confirm this. This code sorts as expected ("{attr}id" is last in the resulting array):

$arr = array(
  "district_name" => "foo",
  "email" => "foo",
  "name" => "foo",
  "number" => "foo",
  "phone" => "foo",
  '{attr}id' => "foo",
  "questions" => "foo",
);

ksort($arr);

var_dump($arr);

Please make sure your source array is okay.

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

1 Comment

You are right, must have been something else in my source code. Thanks

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.