array_key_exists() 函数

2012-08-15   来源:站长日记       编辑:沧海桑田   类别:PHP 教程    转载到:    发表评论

(PHP 4 >= 4.0.7, PHP 5)
array_key_exists — Checks if the given key or index exists in the array
定义和用法
array_key_exists() 函数判断某个数组中是否存在指定的 key,如果该 key 存在,则返回 true,否则返回 false。

bool array_key_exists ( mixed $key , array $search )
array_key_exists() returns TRUE if the given key is set in the array.
key can be any value possible for an array index.

key
Value to check.

search
An array with keys to check.

Return Values
Returns TRUE on success or FALSE on failure.

语法
array_key_exists(key,array)参数 描述
key 必需。规定键名。
array 必需。规定输入的数组。

$a=array("a"=>"Dog","b"=>"Cat");
echo  array_key_exists("a",$a) ? "Key exists!" : "Key does not exist!" ;
?>
输出:Key exists!

 

5.3.0 This function doesn't work with objects anymore, property_exists() should be used in this case.  

0

0
0|0 | 鲜花 VS 砸蛋 | 20阅读 0评论
 
不想登录?直接点击发布即可作为游客留言。
昵称  邮箱 网站 验证码 = 1+1