超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<array_intersectarray_keys>
Last updated: Fri, 22 Jun 2007

array_key_exists

(PHP 4 >= 4.1.0, PHP 5)

array_key_exists -- 检查给定的键名或索引是否存在于数组中

说明

bool array_key_exists ( mixed key, array search)

array_key_exists() 在给定的 key 存在于数组中时返回 TRUEkey 可以是任何能作为数组索引的值。

例子 1. array_key_exists() 例子

<?php
$search_array
= array("first" => 1, "second" => 4);
if (
array_key_exists("first", $search_array)) {
   echo
"The 'first' element is in the array";
}
?>

注: 在 PHP 4.0.6 中本函数名为 key_exists()

参见 isset()array_keys()in_array()




add a note add a note User Contributed Notes
array_key_exists
jeff at procata dot com
11-Oct-2003 03:55
In PHP 4.1.2, passing a NULL for the first parameter will result in an error:

Wrong datatype for first argument in call to array_key_exists

By 4.3.2 this message has been removed.

use short circuit operators to emulate the more current behavior under older versions of PHP:

(is_null($key) || !array_key_exists($key, $search))
26-Jul-2003 01:36
For versions before 4.1.0:

function arrayKeyExists($key, $search) {
  return in_array($key, array_keys($search));
}
17-Jan-2002 10:15
You can't use isset() if the associated value is NULL.

You may be able to use array_key_exists() instead.

<array_intersectarray_keys>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22