1

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

1 Answer 1

2

Something like this should work:

function getTexts()
{
    call_user_func_array(array($this, 'printTextToDashboard'), func_get_args());
}
Sign up to request clarification or add additional context in comments.

1 Comment

or, in php 5.6 (and above): $this->printTextToDashboard(...func_get_args());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.