Fixed #48119 (usort() docs don't mention it now takes a lambda)

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@283436 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Kalle Sommer Nielsen 2009-07-03 18:21:37 +00:00
parent 509d32cd3e
commit 3b0392cafa
2 changed files with 50 additions and 41 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.3 $ -->
<!-- $Revision: 1.4 $ -->
<sect1 xml:id="language.pseudo-types">
<title>Pseudo-types and variables used in this documentation</title>
@ -63,14 +63,16 @@
<para>
Apart from common user-defined function, <function>create_function</function>
can also be used to create an anonymous callback function.
can also be used to create an anonymous callback function. As of PHP 5.3.0
its possible to also pass a closure to a callback parameter.
</para>
<example>
<title>
Callback function examples
</title>
<programlisting role="php">
<para>
<example>
<title>
Callback function examples
</title>
<programlisting role="php">
<![CDATA[
<?php
@ -115,8 +117,42 @@ class B extends A {
call_user_func(array('B', 'parent::who')); // A
?>
]]>
</programlisting>
</example>
</programlisting>
</example>
</para>
<para>
<example>
<title>
Callback example using a Closure
</title>
<programlisting role="php">
<![CDATA[
<?php
// Our closure
$double = function($a) {
return $a * 2;
};
// This is our range of numbers
$numbers = range(1, 5);
// Use the closure as a callback here to
// double the size of each element in our
// range
$new_numbers = array_map($double, $numbers);
print implode(' ', $new_numbers);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
2 4 6 8 10
]]>
</screen>
</example>
</para>
<note>
<simpara>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.22 $ -->
<!-- $Revision: 1.23 $ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.array-map">
<refnamediv>
<refname>array_map</refname>
@ -66,31 +66,6 @@
</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>
It is now possible to use a lambda function as the
<parameter>callback</parameter>.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
@ -127,17 +102,15 @@ Array
</screen>
</example>
<example>
<title><function>array_map</function> using lambda function (as of PHP 5.3.0)</title>
<title><function>array_map</function> using a lambda function (as of PHP 5.3.0)</title>
<programlisting role="php">
<![CDATA[
<?php
/* As of PHP 5.3.0 */
$func = function($value) { return $value * 2; };
$func = function($value) {
return $value * 2;
};
print_r(array_map($func, range(1, 5)));
?>
]]>
</programlisting>