【发布时间】:2018-04-22 09:31:22
【问题描述】:
有没有办法在 php.ini 中调用动态函数。举个例子,让我们猜猜我有一个像下面这样的变量。
$myVar = 'my_test_function';
我有一个名为 myTestFunction() 的函数。有没有办法使用 $myVar 变量的值调用上述函数?如何将该变量构造为 myTestFunction 并使用该变量调用上述函数
【问题讨论】:
有没有办法在 php.ini 中调用动态函数。举个例子,让我们猜猜我有一个像下面这样的变量。
$myVar = 'my_test_function';
我有一个名为 myTestFunction() 的函数。有没有办法使用 $myVar 变量的值调用上述函数?如何将该变量构造为 myTestFunction 并使用该变量调用上述函数
【问题讨论】:
只需执行以下操作:
lcfirst(str_replace('_', '', ucwords($myVar, '_')))();
【讨论】:
先将你的字符串转换为函数名:
$myVar = 'my_test_function';
echo $myVar = str_replace('_', '', ucwords($myVar, '_')); //output myTestFunction
$myVar();
【讨论】: