create_function
Opis
string create_function ( string args, string code )Creates an anonymous function from the parameters passed, and returns a unique name for it.
Parametry
Usually these parameters will be passed as single quote delimited strings. The reason for using single quoted strings, is to protect the variable names from parsing, otherwise, if you use double quotes there will be a need to escape the variable names, e.g. \$avar.
args
The function arguments.
code
The function code.
Przykłady
Or, perhaps to have general handler function that can apply a set of operations to a list of parameters:
Przykład 2. Making a general processing function with create_function()
Powyższy przykład wyświetli:
|
But perhaps the most common use for of lambda-style (anonymous) functions is to create callback functions, for example when using array_walk() or usort()
Przykład 3. Using anonymous functions as callback functions
Powyższy przykład wyświetli:
an array of strings ordered from shorter to longer
Powyższy przykład wyświetli:
sort it from longer to shorter
Powyższy przykład wyświetli:
|
Poprzedni | Spis treści | Następny |
call_user_func | Początek rozdziału |