Reputation: 9183
I have two functions with an optional amount of variables:
function getTexts()
{
$this->printTextToDashboard();
}
function printTextToDashboard()
{
$args = func_get_args();
$argsNum = count($args);
for($i=0; $i < $argsNum; $i++)
{
echo "This is the $i text: "."<br />".$args[$i]."<br />";
}
}
For instance I want to call getTexts like this:
getTexts($name, $lastname, $email);
I know it has something to do with user_func_*
, but I'm unable to implement it.
Thanks in advance
Upvotes: 1
Views: 64
Reputation: 54841
Something like this should work:
function getTexts()
{
call_user_func_array(array($this, 'printTextToDashboard'), func_get_args());
}
Upvotes: 2