[prev in list] [next in list] [prev in thread] [next in thread]
List: php-doc-cvs
Subject: [DOC-CVS] =?utf-8?q?svn:_/phpdoc/en/trunk/reference/array/functions/_array-reduce.xml?=
From: Bob_Weinand <bwoebi () php ! net>
Date: 2014-05-14 20:29:28
Message-ID: svn-bwoebi-1400099368-333542-1687782123 () svn ! php ! net
[Download RAW message or body]
bwoebi Wed, 14 May 2014 20:29:28 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=333542
Log:
Use explicit variable names in code example for array_reduce()
--
Provided by adrien.crivelli@gmail.com
Changed paths:
U phpdoc/en/trunk/reference/array/functions/array-reduce.xml
Modified: phpdoc/en/trunk/reference/array/functions/array-reduce.xml
===================================================================
--- phpdoc/en/trunk/reference/array/functions/array-reduce.xml 2014-05-14 20:13:34 UTC (rev 333541)
+++ phpdoc/en/trunk/reference/array/functions/array-reduce.xml 2014-05-14 20:29:28 UTC (rev 333542)
@@ -116,32 +116,27 @@
<programlisting role="php">
<![CDATA[
<?php
-function rsum($v, $w)
+function sum($carry, $item)
{
- $v += $w;
- return $v;
+ $carry += $item;
+ return $carry;
}
-function rmul($v, $w)
+function multiplication($carry, $item)
{
- $v *= $w;
- return $v;
+ $carry *= $item;
+ return $carry;
}
$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");
+
+var_dump(array_reduce($a, "sum")); // int(15)
+var_dump(array_reduce($a, "multiplication", 10)); // int(1200), because: 10*1*2*3*4*5
+var_dump(array_reduce($x, "sum", "No data to reduce")); // string(17) "No data to reduce"
?>
]]>
</programlisting>
- <para>
- This will result in <varname>$b</varname> containing
- <literal>15</literal>, <varname>$c</varname> containing
- <literal>1200</literal> (= 10*1*2*3*4*5), and <varname>$d</varname>
- containing <literal>No data to reduce</literal>.
- </para>
</example>
</para>
</refsect1>
--
PHP Documentation Commits Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic