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