PHP传递函数名作为参数然后调用函数? [英] PHP pass function name as param then call the function?

查看:31
本文介绍了PHP传递函数名作为参数然后调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to pass a function as a parameter to another function and then call the passed function from within the function...This is probably easier for me to explain in code..I basically want to do something like this:

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

有没有办法做到这一点..我使用的是 PHP 4.3.9

Is there a way to do that.. I am using PHP 4.3.9

谢谢!

推荐答案

我想你正在寻找 call_user_func.

I think you are looking for call_user_func.

PHP 手册中的示例:

An example from the PHP Manual:

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

这篇关于PHP传递函数名作为参数然后调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆