aidan Wed Aug 4 04:36:51 2004 EDT
Modified files: /phpdoc/en/reference/array/functions array-key-exists.xml Log: - 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 http://cvs.php.net/diff.php/phpdoc/en/reference/array/functions/array-key-exists.xml?r1=1.8&r2=1.9&ty=u Index: phpdoc/en/reference/array/functions/array-key-exists.xml diff -u phpdoc/en/reference/array/functions/array-key-exists.xml:1.8 phpdoc/en/reference/array/functions/array-key-exists.xml:1.9 --- phpdoc/en/reference/array/functions/array-key-exists.xml:1.8 Fri Mar 5 21:40:19 2004 +++ phpdoc/en/reference/array/functions/array-key-exists.xml Wed Aug 4 04:36:51 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <!-- splitted from ./en/functions/array.xml, last change in rev 1.119 --> <refentry id="function.array-key-exists"> <refnamediv> @@ -17,7 +17,11 @@ <function>array_key_exists</function> returns &true; if the given <parameter>key</parameter> is set in the array. <parameter>key</parameter> can be any value possible - for an array index. + for an array index. <function>array_key_exists</function> also works + on objects. + </para> + <para> + </para> <para> <example> @@ -25,8 +29,8 @@ <programlisting role="php"> <![CDATA[ <?php -$search_array = array("first" => 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 @@ in PHP 4.0.6. </simpara> </note> + <example> + <title><function>array_key_exists</function> vs <function>isset</function></title> + <para> + <function>isset</function> does not return &true; for array keys + that correspond to a &null; value, while + <function>array_key_exists</function> does. + </para> + <programlisting role="php"> +<![CDATA[ +<?php +$search_array = array('first' => null, 'second' => 4); + +// returns false +isset($search_array['first']) + +// returns true +array_key_exists('first', $search_array); +?> +]]> + </programlisting> + </example> <para> See also <function>isset</function>, <function>array_keys</function>, and