Re: Array key names - can they be called as strings?
| From: | Matt Matijevich | Date: | Thu, 17 Jul 2003 21:48:48 +0000 |
| Subject: | Re: Array key names - can they be called as strings? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-155687@lists.php.net to get a copy of this message | ||
<snip>
The question is the - the assigned string key - is there a way to
retrieve
that in a loop? Foreach, for, while or otherwise?
</snip>
I think this is what you want.
http://www.php.net/manual/en/control-structures.foreach.php
foreach(array_expression as $value) statement
foreach(array_expression as $key => $value) statement
The first form loops over the array given by array_expression. On each
loop, the value of the current element is assigned to $value and the
internal array pointer is advanced by one (so on the next loop, you'll
be looking at the next element).
The second form does the same thing, except that the current element's
key will be assigned to the variable $key on each loop.