Page 1 of 1

create_function, string issue

Posted: Tue Sep 04, 2012 8:11 am
by pedroz
The following code works

Code: Select all

$newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);');

$a = 2; $b = 3;
echo $newfunc($a, $b) . "\n";

However, I am trying to use a string $x to execute $newfunc but it is not working.
How can I use $x sting in the $newfunc ?

Code: Select all

$newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);');

$x = '2,3';
echo $newfunc($x) . "\n";
Thanks

Re: create_function, string issue

Posted: Tue Sep 04, 2012 11:44 am
by Christopher
You can't because the function requires two parameters. $x is just a string that happens to have a comma in it. But PHP does not look inside strings like that.