Due to the fact that you can use it in many ways. Even in the array!
$farr = array( create_function('$x,$y', 'return "some trig: ".(sin($x) + $x*cos($y));'), create_function('$x,$y', 'return "a hypotenuse: ".sqrt($x*$x + $y*$y);'), create_function('$a,$b', $f1), create_function('$a,$b', $f2), create_function('$a,$b', $f3) );
You look at just one example, but using this function is more complicated, you can use it in different ways, which will be easier than using function() .
As an example # 3 on PHP.net
<?php $av = array("the ", "a ", "that ", "this "); array_walk($av, create_function('&$v,$k', '$v = $v . "mango";')); print_r($av); ?>
The above example outputs:
Array ( [0] => the mango [1] => a mango [2] => that mango [3] => this mango )
Joran den houting
source share