mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
- Restructuring
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@131911 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
a09f981d33
commit
5a3d1d65cc
5 changed files with 93 additions and 53 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.4 $ -->
|
||||
<!-- $Revision: 1.5 $ -->
|
||||
<!-- splitted from ./en/functions/funchand.xml, last change in rev 1.10 -->
|
||||
<refentry id="function.call-user-func-array">
|
||||
<refnamediv>
|
||||
|
@ -20,9 +20,12 @@
|
|||
<parameter>function</parameter>, with
|
||||
the parameters in <parameter>paramarr</parameter>.
|
||||
For example:
|
||||
</para>
|
||||
<para>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
function debug($var, $val)
|
||||
echo "***DEBUGGING\nVARIABLE: $var\nVALUE:";
|
||||
if (is_array($val) || is_object($val) || is_resource($val))
|
||||
|
@ -38,6 +41,7 @@ $host = $_SERVER["SERVER_NAME"];
|
|||
call_user_func_array ('debug', array("host", $host));
|
||||
call_user_func_array ('debug', array("c", $c));
|
||||
call_user_func_array ('debug', array("_POST", $_POST));
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.4 $ -->
|
||||
<!-- $Revision: 1.5 $ -->
|
||||
<!-- splitted from ./en/functions/funchand.xml, last change in rev 1.1 -->
|
||||
<refentry id="function.call-user-func">
|
||||
<refnamediv>
|
||||
|
@ -20,14 +20,18 @@
|
|||
Call a user defined function given by the
|
||||
<parameter>function</parameter> parameter. Take the
|
||||
following:
|
||||
</para>
|
||||
<para>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
function barber ($type) {
|
||||
print "You wanted a $type haircut, no problem";
|
||||
}
|
||||
call_user_func ('barber', "mushroom");
|
||||
call_user_func ('barber', "shave");
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
|
@ -36,6 +40,8 @@ call_user_func ('barber', "shave");
|
|||
Object methods may also be invoked statically using this function
|
||||
by passing <literal>array($objectname, $methodname)</literal> to
|
||||
the <parameter>function</parameter> parameter.
|
||||
</para>
|
||||
<para>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.2 $ -->
|
||||
<!-- $Revision: 1.3 $ -->
|
||||
<!-- splitted from ./en/functions/funchand.xml, last change in rev 1.1 -->
|
||||
<refentry id="function.create-function">
|
||||
<refnamediv>
|
||||
|
@ -27,23 +27,31 @@
|
|||
<para>
|
||||
You can use this function, to (for example) create a function
|
||||
from information gathered at run time:
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>
|
||||
Creating an anonymous function with <function>create_function</function>
|
||||
</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$newfunc = create_function('$a,$b','return "ln($a) + ln($b) = ".log($a * $b);');
|
||||
echo "New anonymous function: $newfunc\n";
|
||||
echo $newfunc(2,M_E)."\n";
|
||||
// outputs
|
||||
// New anonymous function: lambda_1
|
||||
// ln(2) + ln(2.718281828459) = 1.6931471805599
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
Or, perhaps to have general handler function that can apply a set
|
||||
of operations to a list of parameters:
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>
|
||||
Making a general processing function with
|
||||
|
@ -51,6 +59,7 @@ echo $newfunc(2,M_E)."\n";
|
|||
</title>
|
||||
<programlisting role="php">
|
||||
<."\n";
|
||||
|
@ -81,12 +90,13 @@ $garr = array(
|
|||
);
|
||||
echo "\nUsing the second array of anonymous functions\n";
|
||||
process("Twas brilling and the slithy toves", "Twas the night", $garr);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
and when you run the code above, the output will be:
|
||||
<informalexample>
|
||||
<programlisting>
|
||||
<para>
|
||||
and when you run the code above, the output will be:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
Using the first array of anonymous functions
|
||||
parameters: 2.3445, M_PI
|
||||
|
@ -102,53 +112,65 @@ Using the second array of anonymous functions
|
|||
CRCs: -725381282 , 1908338681
|
||||
similar(a,b) = 11(45.833333333333%)
|
||||
]]>
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
But perhaps the most common use for of lambda-style (anonymous) functions
|
||||
is to create callback functions, for example when using
|
||||
<function>array_walk</function> or <function>usort</function>
|
||||
<example>
|
||||
<title>Using anonymous functions as callback functions</title>
|
||||
<programlisting role="php">
|
||||
</screen>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
But perhaps the most common use for of lambda-style (anonymous) functions
|
||||
is to create callback functions, for example when using
|
||||
<function>array_walk</function> or <function>usort</function>
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>Using anonymous functions as callback functions</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$av = array("the ","a ","that ","this ");
|
||||
array_walk($av, create_function('&$v,$k','$v = $v."mango";'));
|
||||
print_r($av); // for PHP 3 use var_dump()
|
||||
// outputs:
|
||||
// Array
|
||||
// (
|
||||
// [0] => the mango
|
||||
// [1] => a mango
|
||||
// [2] => that mango
|
||||
// [3] => this mango
|
||||
// )
|
||||
/*
|
||||
outputs:
|
||||
Array
|
||||
(
|
||||
[0] => the mango
|
||||
[1] => a mango
|
||||
[2] => that mango
|
||||
[3] => this mango
|
||||
)
|
||||
*/
|
||||
|
||||
// an array of strings ordered from shorter to longer
|
||||
$sv = array("small","larger","a big string","it is a string thing");
|
||||
print_r($sv);
|
||||
// outputs:
|
||||
// Array
|
||||
// (
|
||||
// [0] => small
|
||||
// [1] => larger
|
||||
// [2] => a big string
|
||||
// [3] => it is a string thing
|
||||
// )
|
||||
/*
|
||||
outputs:
|
||||
Array
|
||||
(
|
||||
[0] => small
|
||||
[1] => larger
|
||||
[2] => a big string
|
||||
[3] => it is a string thing
|
||||
)
|
||||
*/
|
||||
|
||||
// sort it from longer to shorter
|
||||
usort($sv, create_function('$a,$b','return strlen($b) - strlen($a);'));
|
||||
print_r($sv);
|
||||
// outputs:
|
||||
// Array
|
||||
// (
|
||||
// [0] => it is a string thing
|
||||
// [1] => a big string
|
||||
// [2] => larger
|
||||
// [3] => small
|
||||
// )
|
||||
/*
|
||||
outputs:
|
||||
Array
|
||||
(
|
||||
[0] => it is a string thing
|
||||
[1] => a big string
|
||||
[2] => larger
|
||||
[3] => small
|
||||
)
|
||||
*/
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.2 $ -->
|
||||
<!-- $Revision: 1.3 $ -->
|
||||
<!-- splitted from ./en/functions/funchand.xml, last change in rev 1.1 -->
|
||||
<refentry id="function.function-exists">
|
||||
<refnamediv>
|
||||
|
@ -17,17 +17,23 @@
|
|||
<para>
|
||||
Checks the list of defined functions, both built-in (internal) and
|
||||
user-defined, for <parameter>function_name</parameter>. &return.success;
|
||||
</para>
|
||||
<para>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
if (function_exists('imap_open')) {
|
||||
echo "IMAP functions are available.<br>\n";
|
||||
echo "IMAP functions are available.<br />\n";
|
||||
} else {
|
||||
echo "IMAP functions are not available.<br>\n";
|
||||
echo "IMAP functions are not available.<br />\n";
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
</para>
|
||||
<para>
|
||||
Note that a function name may exist even if the function itself
|
||||
is unusable due to configuration or compiling options (with the
|
||||
<link linkend="ref.image">image</link> functions being an example).
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.2 $ -->
|
||||
<!-- $Revision: 1.3 $ -->
|
||||
<!-- splitted from ./en/functions/funchand.xml, last change in rev 1.6 -->
|
||||
<refentry id="function.get-defined-functions">
|
||||
<refnamediv>
|
||||
|
@ -20,9 +20,12 @@
|
|||
internal functions will be accessible via
|
||||
<varname>$arr["internal"]</varname>, and the user defined ones using
|
||||
<varname>$arr["user"]</varname> (see example below).
|
||||
</para>
|
||||
<para>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
function myrow($id, $data) {
|
||||
return "<tr><th>$id</th><td>$data</td></tr>\n";
|
||||
}
|
||||
|
@ -30,14 +33,13 @@ function myrow($id, $data) {
|
|||
$arr = get_defined_functions();
|
||||
|
||||
print_r($arr);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
</para>
|
||||
<para>
|
||||
Will output something along the lines of:
|
||||
<informalexample>
|
||||
<programlisting>
|
||||
</programlisting>
|
||||
<para>
|
||||
Will output something along the lines of:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
Array
|
||||
(
|
||||
|
@ -62,7 +64,7 @@ Array
|
|||
|
||||
)
|
||||
]]>
|
||||
</programlisting>
|
||||
</screen>
|
||||
</informalexample>
|
||||
</para>
|
||||
<para>
|
||||
|
|
Loading…
Reference in a new issue