如何从存储在变量中的字符串调用函数?
2022-08-30 06:02:22
我需要能够调用一个函数,但函数名称存储在变量中,这可能吗?例如:
function foo ()
{
//code here
}
function bar ()
{
//code here
}
$functionName = "foo";
// I need to call the function based on what is $functionName
我需要能够调用一个函数,但函数名称存储在变量中,这可能吗?例如:
function foo ()
{
//code here
}
function bar ()
{
//code here
}
$functionName = "foo";
// I need to call the function based on what is $functionName
我最喜欢的版本是内联版本:
${"variableName"} = 12;
$className->{"propertyName"};
$className->{"methodName"}();
StaticClass::${"propertyName"};
StaticClass::{"methodName"}();
您也可以将变量或表达式放在括号内!