如何从存储在变量中的字符串调用函数? [英] How to call a function from a string stored in a variable?
本文介绍了如何从存储在变量中的字符串调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要能够调用一个函数,但是函数名称存储在变量中,这可能吗?例如:
I need to be able to call a function, but the function name is stored in a variable, is this possible? e.g:
function foo ()
{
//code here
}
function bar ()
{
//code here
}
$functionName = "foo";
// i need to call the function based on what is $functionName
推荐答案
call_user_func($functionName)
这篇关于如何从存储在变量中的字符串调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文