php - 如何调用数组中的所有php函数

标签 php arrays function

如果我有一个名为 myFunctions 的数组,其中包含这样的 php 函数名称...

$myFunctions= array("functionA", "functionB", "functionC", "functionD",....."functionZ");

如何使用该数组调用所有这些函数?

最佳答案

您可以使用 variable functions

PHP supports the concept of variable functions. This means that if a variable name has parentheses appended to it, PHP will look for a function with the same name as whatever the variable evaluates to, and will attempt to execute it. Among other things, this can be used to implement callbacks, function tables, and so forth.

foreach($myFunctions as $func) {
    $func();
}

关于php - 如何调用数组中的所有php函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25578714/

相关文章:

php - 在 php 中创建错误处理程序类

php - 按类别或作者 wordpress 获取帖子

c - 测量缓存延迟

ruby-on-rails - 按 bool 值分组但在 ruby​​ on rails 中更改键

javascript - javascript中的多个函数调用,即combine(foo)(bar)

php - PayPal IPN 不断返回 'INVALID' 代码,无论我做什么

为随机数二维数组创建函数

c - 使用 "beep function"与其他命令并行?

java - 是否建议使用java字符串作为方法间通信的唯一模式

php - 我是否正确查询 MySQL 表?