Skip to content

Commit 596c114

Browse files
Add documentation for array_find RFC (#3465)
* Add `array_find` documentation * Add `array_find_key` documentation * Add `array_any` documentation * Add `array_all` documentation
1 parent 46e3bce commit 596c114

File tree

6 files changed

+561
-3
lines changed

6 files changed

+561
-3
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- $Revision$ -->
3+
<refentry xml:id="function.array-all" xmlns="http://docbook.org/ns/docbook">
4+
<refnamediv>
5+
<refname>array_all</refname>
6+
<refpurpose>Checks if all &array; elements satisfy a callback function</refpurpose>
7+
</refnamediv>
8+
9+
<refsect1 role="description">
10+
&reftitle.description;
11+
<methodsynopsis>
12+
<type>mixed</type><methodname>array_all</methodname>
13+
<methodparam><type>array</type><parameter>array</parameter></methodparam>
14+
<methodparam><type>callable</type><parameter>callback</parameter></methodparam>
15+
</methodsynopsis>
16+
<simpara>
17+
<function>array_all</function> returns &true;, if the given
18+
<parameter>callback</parameter> returns &true; for all elements.
19+
Otherwise the function returns &false;.
20+
</simpara>
21+
</refsect1>
22+
23+
<refsect1 role="parameters">
24+
&reftitle.parameters;
25+
<variablelist>
26+
<varlistentry>
27+
<term><parameter>array</parameter></term>
28+
<listitem>
29+
<simpara>
30+
The &array; that should be searched.
31+
</simpara>
32+
</listitem>
33+
</varlistentry>
34+
<varlistentry>
35+
<term><parameter>callback</parameter></term>
36+
<listitem>
37+
<para>
38+
The callback function to call to check each element, which must be
39+
<methodsynopsis>
40+
<type>bool</type><methodname><replaceable>callback</replaceable></methodname>
41+
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
42+
<methodparam><type>mixed</type><parameter>key</parameter></methodparam>
43+
</methodsynopsis>
44+
If this function returns &false;, &false; is returned from
45+
<function>array_all</function> and the callback will not be called for
46+
further elements.
47+
</para>
48+
</listitem>
49+
</varlistentry>
50+
</variablelist>
51+
</refsect1>
52+
53+
<refsect1 role="returnvalues">
54+
&reftitle.returnvalues;
55+
<simpara>
56+
The function returns &true;, if <parameter>callback</parameter> returns
57+
&true; for all elements. Otherwise the function returns &false;.
58+
</simpara>
59+
</refsect1>
60+
61+
<refsect1 role="examples">
62+
&reftitle.examples;
63+
<example>
64+
<title><function>array_all</function> example</title>
65+
<programlisting role="php">
66+
<![CDATA[
67+
<?php
68+
$array = [
69+
'a' => 'dog',
70+
'b' => 'cat',
71+
'c' => 'cow',
72+
'd' => 'duck',
73+
'e' => 'goose',
74+
'f' => 'elephant'
75+
];
76+
77+
// Check, if all animal names are shorter than 12 letters.
78+
var_dump(array_all($array, function (string $value) {
79+
return strlen($value) < 12;
80+
}));
81+
82+
// Check, if all animal names are longer than 5 letters.
83+
var_dump(array_all($array, function (string $value) {
84+
return strlen($value) > 5;
85+
}));
86+
87+
// Check, if all array keys are strings.
88+
var_dump(array_all($array, function (string $value, $key) {
89+
return is_string($key);
90+
}));
91+
?>
92+
]]>
93+
</programlisting>
94+
&example.outputs;
95+
<screen>
96+
<![CDATA[
97+
bool(true)
98+
bool(false)
99+
bool(true)
100+
]]>
101+
</screen>
102+
</example>
103+
</refsect1>
104+
105+
<refsect1 role="seealso">
106+
&reftitle.seealso;
107+
<simplelist>
108+
<member><function>array_any</function></member>
109+
<member><function>array_filter</function></member>
110+
<member><function>array_find</function></member>
111+
<member><function>array_find_key</function></member>
112+
</simplelist>
113+
</refsect1>
114+
</refentry>
115+
<!-- Keep this comment at the end of the file
116+
Local variables:
117+
mode: sgml
118+
sgml-omittag:t
119+
sgml-shorttag:t
120+
sgml-minimize-attributes:nil
121+
sgml-always-quote-attributes:t
122+
sgml-indent-step:1
123+
sgml-indent-data:t
124+
indent-tabs-mode:nil
125+
sgml-parent-document:nil
126+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
127+
sgml-exposed-tags:nil
128+
sgml-local-catalogs:nil
129+
sgml-local-ecat-files:nil
130+
End:
131+
vim600: syn=xml fen fdm=syntax fdl=2 si
132+
vim: et tw=78 syn=sgml
133+
vi: ts=1 sw=1
134+
-->
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- $Revision$ -->
3+
<refentry xml:id="function.array-any" xmlns="http://docbook.org/ns/docbook">
4+
<refnamediv>
5+
<refname>array_any</refname>
6+
<refpurpose>Checks if at least one &array; element satisfies a callback function</refpurpose>
7+
</refnamediv>
8+
9+
<refsect1 role="description">
10+
&reftitle.description;
11+
<methodsynopsis>
12+
<type>mixed</type><methodname>array_any</methodname>
13+
<methodparam><type>array</type><parameter>array</parameter></methodparam>
14+
<methodparam><type>callable</type><parameter>callback</parameter></methodparam>
15+
</methodsynopsis>
16+
<simpara>
17+
<function>array_any</function> returns &true;, if the given
18+
<parameter>callback</parameter> returns &true; for any element.
19+
Otherwise the function returns &false;.
20+
</simpara>
21+
</refsect1>
22+
23+
<refsect1 role="parameters">
24+
&reftitle.parameters;
25+
<variablelist>
26+
<varlistentry>
27+
<term><parameter>array</parameter></term>
28+
<listitem>
29+
<simpara>
30+
The &array; that should be searched.
31+
</simpara>
32+
</listitem>
33+
</varlistentry>
34+
<varlistentry>
35+
<term><parameter>callback</parameter></term>
36+
<listitem>
37+
<para>
38+
The callback function to call to check each element, which must be
39+
<methodsynopsis>
40+
<type>bool</type><methodname><replaceable>callback</replaceable></methodname>
41+
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
42+
<methodparam><type>mixed</type><parameter>key</parameter></methodparam>
43+
</methodsynopsis>
44+
If this function returns &true;, &true; is returned from
45+
<function>array_any</function> and the callback will not be called for
46+
further elements.
47+
</para>
48+
</listitem>
49+
</varlistentry>
50+
</variablelist>
51+
</refsect1>
52+
53+
<refsect1 role="returnvalues">
54+
&reftitle.returnvalues;
55+
<simpara>
56+
The function returns &true;, if there is at least one element for which
57+
<parameter>callback</parameter> returns &true;. Otherwise the function
58+
returns &false;.
59+
</simpara>
60+
</refsect1>
61+
62+
<refsect1 role="examples">
63+
&reftitle.examples;
64+
<example>
65+
<title><function>array_any</function> example</title>
66+
<programlisting role="php">
67+
<![CDATA[
68+
<?php
69+
$array = [
70+
'a' => 'dog',
71+
'b' => 'cat',
72+
'c' => 'cow',
73+
'd' => 'duck',
74+
'e' => 'goose',
75+
'f' => 'elephant'
76+
];
77+
78+
// Check, if any animal name is longer than 5 letters.
79+
var_dump(array_any($array, function (string $value) {
80+
return strlen($value) > 5;
81+
}));
82+
83+
// Check, if any animal name is shorter than 3 letters.
84+
var_dump(array_any($array, function (string $value) {
85+
return strlen($value) < 3;
86+
}));
87+
88+
// Check, if any array key is not a string.
89+
var_dump(array_any($array, function (string $value, $key) {
90+
return !is_string($key);
91+
}));
92+
?>
93+
]]>
94+
</programlisting>
95+
&example.outputs;
96+
<screen>
97+
<![CDATA[
98+
bool(true)
99+
bool(false)
100+
bool(false)
101+
]]>
102+
</screen>
103+
</example>
104+
</refsect1>
105+
106+
<refsect1 role="seealso">
107+
&reftitle.seealso;
108+
<simplelist>
109+
<member><function>array_all</function></member>
110+
<member><function>array_filter</function></member>
111+
<member><function>array_find</function></member>
112+
<member><function>array_find_key</function></member>
113+
</simplelist>
114+
</refsect1>
115+
</refentry>
116+
<!-- Keep this comment at the end of the file
117+
Local variables:
118+
mode: sgml
119+
sgml-omittag:t
120+
sgml-shorttag:t
121+
sgml-minimize-attributes:nil
122+
sgml-always-quote-attributes:t
123+
sgml-indent-step:1
124+
sgml-indent-data:t
125+
indent-tabs-mode:nil
126+
sgml-parent-document:nil
127+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
128+
sgml-exposed-tags:nil
129+
sgml-local-catalogs:nil
130+
sgml-local-ecat-files:nil
131+
End:
132+
vim600: syn=xml fen fdm=syntax fdl=2 si
133+
vim: et tw=78 syn=sgml
134+
vi: ts=1 sw=1
135+
-->

reference/array/functions/array-filter.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<refname>array_filter</refname>
66
<refpurpose>Filters elements of an array using a callback function</refpurpose>
77
</refnamediv>
8-
8+
99
<refsect1 role="description">
1010
&reftitle.description;
1111
<methodsynopsis>
@@ -201,7 +201,7 @@ Array
201201
</screen>
202202
</example>
203203
<example>
204-
<title><function>array_filter</function> with
204+
<title><function>array_filter</function> with
205205
<parameter>mode</parameter></title>
206206
<programlisting role="php">
207207
<![CDATA[
@@ -253,9 +253,10 @@ array(2) {
253253
<para>
254254
<simplelist>
255255
<member><function>array_intersect</function></member>
256+
<member><function>array_find</function></member>
257+
<member><function>array_any</function></member>
256258
<member><function>array_map</function></member>
257259
<member><function>array_reduce</function></member>
258-
<member><function>array_walk</function></member>
259260
</simplelist>
260261
</para>
261262
</refsect1>

0 commit comments

Comments
 (0)