Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
1  
On which place you want {attr}id to be ? –  hsz Apr 11 '11 at 9:25
    
It gets sorted here to end of the array. –  Artefacto Apr 11 '11 at 9:29
    
uksort()? ....... –  Peter Lindqvist Apr 11 '11 at 9:30

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
You are right, must have been something else in my source code. Thanks –  Tirithen Apr 11 '11 at 14:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.