PHP 将函数名称作为参数传递然后调用该函数?

标签 php function parameters

我需要将一个函数作为参数传递给另一个函数,然后从函数内部调用传递的函数...这对我来说在代码中解释起来可能更容易...我基本上想做这样的事情:

function ($functionToBeCalled)
{
   call($functionToBeCalled,additional_params);
}

有没有办法做到这一点..我正在使用 PHP 4.3.9

谢谢!

最佳答案

我想你在找call_user_func .

PHP 手册中的示例:

<?php
function barber($type) {
    echo "You wanted a $type haircut, no problem";
}
call_user_func('barber', "mushroom");
call_user_func('barber', "shave");
?>

关于PHP 将函数名称作为参数传递然后调用该函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/627775/

相关文章:

php - 未定义的属性:Illuminate\Database\Eloquent\Relations\BelongsTo::$center_name

function - Commodore 64 BASIC 中的多行功能

java - 启动JVM时的-Xms和-Xmx参数是什么?

Powershell:找不到接受参数 “test”的位置参数

php - 如何在我的网站上显示我的Facebook Wall

php - in_array 组合值 ('test' ,'value' )

javascript - PHP AJAX 无法在 'setrequestheader' 上执行 'xmlhttprequest' 对象的状态必须打开

python - 为什么不允许在函数中使用 "from ... import *"?

c - 无效函数错误?

oracle - 可选的输出游标作为参数