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

查看:103
本文介绍了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天全站免登陆