key 从关联数组中取得键名 php函数


key

(PHP 4, PHP 5)

key从关联数组中取得键名

说明

mixed key ( array &$array )

key() 返回数组中当前单元的键名。

Example #1 key() 例子

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



相关阅读:
krsort 对数组按照键名逆向排序
ksort 对数组按照键名排序
lcg_value 组合线性同余发生器
lchgrp Changes group ownership of symlink
lchown Changes user ownership of symlink
ldap_8859_to_t61 Translate 8859 characters to t61 characters
ldap_add Add entries to LDAP directory
ldap_bind Bind to LDAP directory
ldap_close 别名 ldap_unbind
ldap_compare Compare value of attribute found in entry specified with DN
ldap_connect Connect to an LDAP server
ldap_count_entries Count the number of entries in a search
ldap_delete Delete an entry from a directory
ldap_dn2ufn Convert DN to User Friendly Naming format
快速导航

Copyright © 2016 phpStudy |