从关联数组中取得键名

来源:互联网 发布:商家怎么找淘宝客 编辑:程序博客网 时间:2024/06/09 11:32

<?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()