I am looking for something similar to the solution here >> Call function from string stored in a variable, however with one difference :
I would like to pass a parameter as well.
For example :
function foo($myvar) {
}
$function = 'foo';
$values = Array('myvar'=>1, 'myvar2'=>2);
if(function_exists($function)) {
// call the function using $function,
// and pass the value $values -- aka $function($values)
}
Any workable solution would be greatly appreciated. Ideally, I would like to use it with classes as follows :
class bar {
function foo($myvar) {
}
}
$function = 'foo';
$values = Array('myvar'=>1, 'myvar2'=>2);
if(function_exists($function)) {
// call the function using $function,
// and pass the value $values -- aka $bar::$function($values)
}