From ce520e68965991d89c7a1d673851c97161633a36 Mon Sep 17 00:00:00 2001 From: Aidan Lister Date: Wed, 4 Aug 2004 08:36:51 +0000 Subject: [PATCH] - Updated the first example with PEAR CS - Added a line to the intro stating the method works fine with objects - Added second example with information about the differences between isset git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@165216 c90b9560-bf6c-de11-be94-00142212c4b1 --- .../array/functions/array-key-exists.xml | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/reference/array/functions/array-key-exists.xml b/reference/array/functions/array-key-exists.xml index 7c3b7e5378..e8cc3b8e79 100644 --- a/reference/array/functions/array-key-exists.xml +++ b/reference/array/functions/array-key-exists.xml @@ -1,5 +1,5 @@ - + @@ -17,7 +17,11 @@ array_key_exists returns &true; if the given key is set in the array. key can be any value possible - for an array index. + for an array index. array_key_exists also works + on objects. + + + @@ -25,8 +29,8 @@ 1, "second" => 4); -if (array_key_exists("first", $search_array)) { +$search_array = array('first' => 1, 'second' => 4); +if (array_key_exists('first', $search_array)) { echo "The 'first' element is in the array"; } ?> @@ -40,6 +44,27 @@ if (array_key_exists("first", $search_array)) { in PHP 4.0.6. + + <function>array_key_exists</function> vs <function>isset</function> + + isset does not return &true; for array keys + that correspond to a &null; value, while + array_key_exists does. + + + null, 'second' => 4); + +// returns false +isset($search_array['first']) + +// returns true +array_key_exists('first', $search_array); +?> +]]> + + See also isset, array_keys, and