我需要能够调用一个函数,但函数名存储在一个变量中,这可能吗?例如:
function foo ()
{
//code here
}
function bar ()
{
//code here
}
$functionName = "foo";
// i need to call the function based on what is $functionName
任何帮助都会很棒.
谢谢!
我不知道如何解释这一点,但简单来说,我看到人们{$variable}在输出值时使用.我注意到{$variable}一切都不起作用.我们应该何时使用{$variable}?
我试着在foo()里面调用这样的字符串:
echo "This is a ${foo()} car";
function foo() {
return "blue";
}
Run Code Online (Sandbox Code Playgroud)
但是,它最终会出现语法错误.
我在这里找到了类似的东西,但不完全是我需要的东西:
echo "This is the value of the var named by the return value of getName(): {${getName()}}";
Run Code Online (Sandbox Code Playgroud)
这有可能吗?