Re: Simple array question
| From: | pete M | Date: | Thu, 23 Oct 2003 09:45:09 +0000 |
| Subject: | Re: Simple array question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-167241@lists.php.net to get a copy of this message | ||
$array = array(
'fruit1' => 'apple',
'fruit2' => 'orange',
'fruit3' => 'grape',
'fruit4' => 'apple',
'fruit5' => 'apple');
// this cycle echoes all associative array
// key where value equals "apple"
while ($fruit_name = current($array)) {
if ($fruit_name == 'apple') {
echo key($array).'<br>';
}
next($array);
}
René fournier wrote:
Is there a simple way to return the key (name) of one element in an array? I looked up key() in the docs, but there are no examples or notes... Thanks. ...Rene