- 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
This commit is contained in:
Aidan Lister 2004-08-04 08:36:51 +00:00
parent ea7277e25c
commit ce520e6896

View file

@ -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 @@ if (array_key_exists("first", $search_array)) {
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