PHP pass function name as param then call the function?

前端 未结 7 1672
感动是毒
感动是毒 2020-11-29 03:58

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..

7条回答
  •  醉梦人生
    2020-11-29 04:36

    function foo($function) {
      $function(" World");
    }
    function bar($params) {
      echo "Hello".$params;
    }
    
    $variable = 'bar';
    foo($variable);
    

    Additionally, you can do it this way. See variable functions.

提交回复
热议问题