1
0
mirror of https://github.com/php/doc-zh.git synced 2026-03-25 23:52:17 +01:00
Files
archived-doc-zh/reference/array/functions/array-reduce.xml
Dai Jie 264ee58391 Sync array functions .
git-svn-id: https://svn.php.net/repository/phpdoc/zh/trunk@327980 c90b9560-bf6c-de11-be94-00142212c4b1
2012-10-10 12:54:58 +00:00

163 lines
4.4 KiB
XML
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- $Author$ -->
<!-- EN-Revision: 5faa7a6747bca628b3bdcc9f93aec5603b65581f Maintainer: dallas Status: ready -->
<refentry xml:id="function.array-reduce" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>array_reduce</refname>
<refpurpose>用回调函数迭代地将数组简化为单一的值</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>mixed</type><methodname>array_reduce</methodname>
<methodparam><type>array</type><parameter>input</parameter></methodparam>
<methodparam><type>callable</type><parameter>function</parameter></methodparam>
<methodparam choice="opt"><type>mixed</type><parameter>initial</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
<para>
<function>array_reduce</function> 将回调函数
<parameter>function</parameter> 迭代地作用到
<parameter>input</parameter> 数组中的每一个单元中,从而将数组简化为单一的值。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>input</parameter></term>
<listitem>
<para>
The input array.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>function</parameter></term>
<listitem>
<para>
The callback function.
</para>
<methodsynopsis>
<type>mixed</type><methodname><replaceable>callback</replaceable></methodname>
<methodparam><type>mixed</type><parameter role="reference">result</parameter></methodparam>
<methodparam><type>mixed</type><parameter>item</parameter></methodparam>
</methodsynopsis>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>initial</parameter></term>
<listitem>
<para>
如果指定了可选参数
<parameter>initial</parameter>,该参数将被当成是数组中的第一个值来处理,或者如果数组为空的话就作为最终返回值。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
返回结果值。
</para>
<para>
<parameter>initial</parameter> 参数,<function>array_reduce</function> 返回 &null;
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>5.3.0</entry>
<entry>
Changed <parameter>initial</parameter> to allow <type>mixed</type>, previously <type>integer</type>.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>array_reduce</function> 例子</title>
<programlisting role="php">
<![CDATA[
<?php
function rsum($v, $w)
{
$v += $w;
return $v;
}
function rmul($v, $w)
{
$v *= $w;
return $v;
}
$a = array(1, 2, 3, 4, 5);
$x = array();
$b = array_reduce($a, "rsum");
$c = array_reduce($a, "rmul", 10);
$d = array_reduce($x, "rsum", "No data to reduce");
?>
]]>
</programlisting>
<para>
这将使 <varname>$b</varname> 的值为
<literal>15</literal><varname>$c</varname> 的值为
<literal>1200</literal>= 10*1*2*3*4*5以及
<varname>$d</varname> 的值为 <literal>1</literal>
</para>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>array_filter</function></member>
<member><function>array_map</function></member>
<member><function>array_unique</function></member>
<member><function>array_count_values</function></member>
</simplelist>
</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:"~/.phpdoc/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
-->