note 20818 deleted from function.list by wez
| From: | wez@php.net | Date: | Thu, 15 May 2003 20:11:33 +0000 |
| Subject: | note 20818 deleted from function.list by wez | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-48038@lists.php.net to get a copy of this message | ||
I agree that it would be nice if
list($nums['one'], $nums['two']) = array(1,2);
gave
Array
(
[one] => 1
[two] => 2
)
and not
Array
(
[two] => 2
[one] => 1
)
but we're basically complaining about how PHP is ordering its actions, that is, adding elements
to the array. Since PHP arrays have no inherent order we must sort them as we wish.
A few posts back there was an example similar to this:
list($fields[], $fields[]) = array(1,2);
This one is really living dangerously because there's really no documented order that $fields
will receive 1 or 2. Is it
$fields[] = 1; // put at index 0
$fields[] = 2; // put at index 1
or
$fields[] = 2; // put at index 0
$fields[] = 1; // put at index 1
or will it change in the next PHP version?
I say DON'T do this, explicitly name your indexes and then either sort your array or iterate
using for with an index.
Don't use foreach or while(list() = each()) and expect the values to appear in a certain order
unless you've ordered (sorted) them.