Entry
How do you pass a function name as an argument to another function and then call the passed function? This would be similar to a function pointer in C
May 15th, 2000 10:16
Robert Ames, xendra .com, http://www.php.net/manual/functions.variable-functions.php
Believe it or not, this is really simple:
function do_something(){
echo "done";
}
function something_else(){
echo "we did something else";
}
function test_dynamic_functions() {
$which_function = "do_something";
$which_function();
$which_function = "something_else";
$which_function();
}
Of course you can pass command line parameters and stuff, if
necessary. The trick is to use the form "$variable_name()", making
sure to have parenthesis after the variable name, and make sure that
variable name has a valid function name.