mirror of
https://github.com/php/doc-pt_br.git
synced 2026-04-29 03:03:23 +02:00
e5ed35c5de
git-svn-id: https://svn.php.net/repository/phpdoc/pt_BR/trunk@94787 c90b9560-bf6c-de11-be94-00142212c4b1
85 lines
2.5 KiB
XML
85 lines
2.5 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- EN-Revision: 1.4 Maintainer: lucasr Status: ready -->
|
|
<!-- splitted from ./pt_BR/functions/array.xml, last change in rev 1.1 -->
|
|
<!-- last change to 'array-reduce' in en/ tree in rev 1.2 -->
|
|
<refentry id="function.array-reduce">
|
|
<refnamediv>
|
|
<refname>array_reduce</refname>
|
|
<refpurpose>
|
|
Reduz um array para um único elemento através de um processo iterativo
|
|
utilizando uma função.
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Descrição</title>
|
|
<methodsynopsis>
|
|
<type>mixed</type><methodname>array_reduce</methodname>
|
|
<methodparam><type>array</type><parameter>input</parameter></methodparam>
|
|
<methodparam><type>mixed</type><parameter>callback</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>initial</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>array_reduce</function> aplica iterativamente a função
|
|
<parameter>callback</parameter> nos elementos de <parameter>input</parameter>,
|
|
de forma a reduzi-lo a um único valor. Se o argumento opcional <parameter>initial</parameter>
|
|
for passado, ele será utilizado no início do processo, ou como
|
|
um resultado final se o array estiver vazio.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Exemplo de <function>array_reduce</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
function soma($v, $w) {
|
|
$v += $w;
|
|
return $v;
|
|
}
|
|
|
|
function multiplicacao($v, $w) {
|
|
$v *= $w;
|
|
return $v;
|
|
}
|
|
|
|
$a = array(1, 2, 3, 4, 5);
|
|
$x = array();
|
|
$b = array_reduce($a, "soma");
|
|
$c = array_reduce($a, "multiplicacao", 10);
|
|
$d = array_reduce($x, "soma", 1);
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
Isso resultará em <varname>$b</varname> contendo
|
|
<literal>15</literal>, <varname>$c</varname> contendo
|
|
<literal>1200</literal> (= 1*2*3*4*5*10), e
|
|
<varname>$d</varname> contendo <literal>1</literal>.
|
|
</para>
|
|
<para>
|
|
Veja também <function>array_filter</function>,
|
|
<function>array_map</function>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|