如何在不使用create_function的情况下重写示例? [英] How to rewrite an example without the use of create_function?
问题描述
当查看PHP的 create_function 时,它说:
When looking at PHP's create_function it says:
如果您使用的是PHP 5.3.0或更高版本,则本机匿名函数应该改为使用.
If you are using PHP 5.3.0 or newer a native anonymous function should be used instead.
我想使用anonymous function
重新创建create_function
的相同功能.我看不到方法,或者我是否正确采用这种方法.
I want to recreate same functionality of create_function
but using an anonymous function
. I do not see how, or if I am approaching it correctly.
本质上,如何更改以下内容,以使我不再使用create_function
,但仍然可以输入要使用自己的参数求值的自由格式公式?
In essence, how do I change the following so that I no longer use create_function
but still can enter free-form formula that I want to be evaluated with my own parameters?
$newfunc = create_function(
'$a,$b',
'return "ln($a) + ln($b) = " . log($a * $b);'
);
echo $newfunc(2, M_E) . "\n";
示例取自PHP的create_function
页.
注意:
在上面的示例中,我可以传入一个任意字符串,并为我编译它.我可以不使用create_function
来做到这一点吗?
It looks like with the above example I can pass in an arbitrary string, and have it be compiled for me. Can I somehow do this without the use of create_function
?
推荐答案
$newfunc = function($a, $b) {
return "ln($a) + ln($b) = " . log($a * $b);
}
echo $newfunc(2, M_E) . "\n";
这篇关于如何在不使用create_function的情况下重写示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!