reference/array/functions/array-key-exists.xml
73048c75fbe328342b74f0ffb0a0c85c477f5cde
...
...
@@ -1,6 +1,6 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.array-key-exists">
3
+
<refentry xml:id="function.array-key-exists" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
5
5
<refname>array_key_exists</refname>
6
6
<refpurpose>Checks if the given key or index exists in the array</refpurpose>
...
...
@@ -10,7 +10,7 @@
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
12
<type>bool</type><methodname>array_key_exists</methodname>
13
-
<methodparam><type>mixed</type><parameter>key</parameter></methodparam>
13
+
<methodparam><type class="union"><type>string</type><type>int</type><type>float</type><type>bool</type><type>resource</type><type>null</type></type><parameter>key</parameter></methodparam>
14
14
<methodparam><type>array</type><parameter>array</parameter></methodparam>
15
15
</methodsynopsis>
16
16
<para>
...
...
@@ -50,6 +50,49 @@
50
50
<para>
51
51
&return.success;
52
52
</para>
53
+
<note>
54
+
<para>
55
+
<function>array_key_exists</function> will search for the keys in the first dimension only.
56
+
Nested keys in multidimensional arrays will not be found.
57
+
</para>
58
+
</note>
59
+
</refsect1>
60
+

61
+
<refsect1 role="changelog">
62
+
&reftitle.changelog;
63
+
<informaltable>
64
+
<tgroup cols="2">
65
+
<thead>
66
+
<row>
67
+
<entry>&Version;</entry>
68
+
<entry>&Description;</entry>
69
+
</row>
70
+
</thead>
71
+
<tbody>
72
+
<row>
73
+
<entry>8.0.0</entry>
74
+
<entry>
75
+
The <parameter>key</parameter> parameter now accepts
76
+
<type>bool</type>, <type>float</type>, <type>int</type>,
77
+
<type>null</type>, <type>resource</type>, and
78
+
<type>string</type> as arguments.
79
+
</entry>
80
+
</row>
81
+
<row>
82
+
<entry>8.0.0</entry>
83
+
<entry>
84
+
Passing an <type>object</type> to the <parameter>array</parameter> parameter is no longer supported.
85
+
</entry>
86
+
</row>
87
+
<row>
88
+
<entry>7.4.0</entry>
89
+
<entry>
90
+
Passing an <type>object</type> to the <parameter>array</parameter> parameter has been deprecated. Use <function>property_exists</function> instead.
91
+
</entry>
92
+
</row>
93
+
</tbody>
94
+
</tgroup>
95
+
</informaltable>
53
96
</refsect1>
54
97

55
98
<refsect1 role="examples">
...
...
@@ -60,13 +103,17 @@
60
103
<programlisting role="php">
61
104
<![CDATA[
62
105
<?php
63
-
$search_array = array('first' => 1, 'second' => 4);
64
-
if (array_key_exists('first', $search_array)) {
65
-
echo "The 'first' element is in the array";
66
-
}
106
+
$searchArray = ['first' => 1, 'second' => 4];
107
+
var_dump(array_key_exists('first', $searchArray));
67
108
?>
68
109
]]>
69
110
</programlisting>
111
+
&example.outputs;
112
+
<screen>
113
+
<![CDATA[
114
+
bool(true)
115
+
]]>
116
+
</screen>
70
117
</example>
71
118
</para>
72
119
<example>
...
...
@@ -79,37 +126,23 @@ if (array_key_exists('first', $search_array)) {
79
126
<programlisting role="php">
80
127
<![CDATA[
81
128
<?php
82
-
$search_array = array('first' => null, 'second' => 4);
129
+
$searchArray = ['first' => null, 'second' => 4];
83
130

84
-
// returns false
85
-
isset($search_array['first']);
86
-

87
-
// returns true
88
-
array_key_exists('first', $search_array);
131
+
var_dump(isset($searchArray['first']));
132
+
var_dump(array_key_exists('first', $searchArray));
89
133
?>
90
134
]]>
91
135
</programlisting>
136
+
&example.outputs;
137
+
<screen>
138
+
<![CDATA[
139
+
bool(false)
140
+
bool(true)
141
+
]]>
142
+
</screen>
92
143
</example>
93
144
</refsect1>
94
145

95
-
<refsect1 role="notes">
96
-
&reftitle.notes;
97
-
<note>
98
-
<para>
99
-
For backward compatibility reasons, <function>array_key_exists</function>
100
-
will also return &true; if <parameter>key</parameter> is a property
101
-
defined within an <type>object</type> given as
102
-
<parameter>array</parameter>. This behaviour should not be relied upon,
103
-
and care should be taken to ensure that <parameter>array</parameter> is
104
-
an <type>array</type>.
105
-
</para>
106
-
<para>
107
-
To check whether a property exists in an object, use
108
-
<function>property_exists</function>.
109
-
</para>
110
-
</note>
111
-
</refsect1>
112
-

113
146
<refsect1 role="seealso">
114
147
&reftitle.seealso;
115
148
<para>
...
...
@@ -122,7 +155,6 @@ array_key_exists('first', $search_array);
122
155
</para>
123
156
</refsect1>
124
157
</refentry>
125
-

126
158
<!-- Keep this comment at the end of the file
127
159
Local variables:
128
160
mode: sgml
129
161