PHP pass function name as param then call the function? PHP pass function name as param then call the function? php php

PHP pass function name as param then call the function?


I think you are looking for call_user_func.

An example from the PHP Manual:

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


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.


In php this is very simple.

<?phpfunction here() {  print 'here';}function dynamo($name) { $name();}//Will workdynamo('here');//Will faildynamo('not_here');