从关联数组中取得键名

<?php
$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);
}
?>

 

参见 current() 和 next()

posted @ 2013-01-26 15:36  芭菲雨  阅读(153)  评论(0编辑  收藏  举报