faqts : Computers : Programming : Languages : PHP : Function Libraries

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 8 people (88%) answered Yes
Recently 1 of 1 people (100%) answered Yes

Entry

Is the order of entries in an associative array guaranteed?
What order are entries in an associative array returned by each()?

Aug 4th, 1999 08:16
Nathan Wallace, John Coggeshall, Teodor Cimpoesu, Rasmus Lerdorf


Say you have something like this:

    $myarray['a'] = 'a';
    $myarray['b'] = 'b';
    $myarray['c'] = 'c';

and do this:

    reset($myarray);
    while(list($key, $val) = each($myarray)) echo "Key: $key<br>";

It will print

    Key: a
    Key: b
    Key: c

This first in first out order is guaranteed.