Functions created by create_function
Use PHP's built-in function to create_function the created function.
Create_function (' $item ', ' return $item; ')
Let me ask you something. Why do you create the function parameter list and function body with quotation marks??
Reply to discussion (solution)
String Create_function (String $args, String $code)
Two parameters are all strings
The arguments that are submitted to the function are not and can be variables.
Because create_function requires the passing of 2 string arguments
Your code is equivalent to
function tmp ($item) {return $item;} $b = Array_map (' tmp ', $a);
You can do it with a closed bag.
$b = Array_map (function ($item) {return $item;}, $a);
The arguments that are submitted to the function are not and can be variables.
$item is already a variable submitted to an anonymous function.
$a =array (100,200,300);
$b =array_map (create_function (' $item ', ' return $item; '), $a);
You mean to say (' $item ', ' return $item; ') The two of them are just the two parameters of the Create_function function, and it will automatically create this function inside.
$a =array (100,200,300);
$b =array_map (create_function (' $item ', ' return $item; '), $a);
Var_dump ($b);
Create_function required to pass in two strings but I have a $ A argument here 100 200 300 is a numeric type Yes help
function tmp ($item) {return $item;}
$b = Array_map (' tmp ', $a);
Do you have any questions about it?
Create_function requires two strings to be passed in
Does not mean that a function produced by Create_function also requires the passing of two strings
Create_function requires two strings to be passed in, namely: The parameter list of the anonymous function and the function body
$a =array (100,200,300);
$b =array_map (create_function (' $item ', ' return $item; '), $a);
Var_dump ($b);
Create_function required to pass in two strings but I have a $ A argument here 100 200 300 is a numeric type Yes help
You seem to confuse a concept:
Create_function is the creation of an anonymous function, which is itself (create_function) is a function that needs to pass in a parameter that is a string.
The parameters of the created function are the parameters you want to pass, that is, the function parameter, 100,200,300 is the argument to the created function, because the anonymous function is created directly using the parameter, so passed in is a numeric type, the use of numerical type. If the pass is not a numeric value, for example, a string of 0123, because of the * operator, it will first be converted to a numeric value and then operation:
Please see:
$a =array (100,200, "011");
$b =array_map (create_function (' $item ', ' return $item; '), $a);
Var_dump ($b);
Thank you for understanding. Yes, there's one more question I'm a beginner. There are a lot of people who don't understand that the parameters of the local function are defined by variables.
Yes, it's all defined in the form of a variable.
Thank you so much for the top guys.
Silent Collection