class example()
{
function shout($var)
{
echo 'shout'.$var;
}
function whisper($var, $bool)
{
if($bool)
{
echo $var;
}
}
}
$obj = new example();
if($var)
{
$func = $obj->shout();
}else
{
$func = $obj->whisper();
}
I want to prepare the function variable first for later use instead of putting conditions in a loop. Is there a possible way to do it?
You can put the function name in a string:
Later on:
You can also use a callback:
Later:
or: