Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think they are a little more complex than regular hash maps.

1) They keys can be integers or unicode strings (ordering works differently for these two cases)

2) The keys are not necessarily ordered (see ksort and krsort functions, for example).



They are ordered by insertion. That's different from for instance objects in Javascript.


Not really

    $arr = array();
    $arr[0] = 'cat';
    $arr[2] = 'dog';
    $arr[1] = 'fish';

    krsort($arr);

    var_dump($arr);
Outputs:

    array(3) 
    {
        [2]=> string(3) "dog" 
        [1]=> string(4) "fish" 
        [0]=> string(3) "cat" 
    }


Well you are explicitly sorting the array by keys, so its not like you are contradicting his sentence. Remove the krsort() call and your "not really" becomes "example".




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: