0

Given the function bar takes a variable number of arguments. How can foo be implemented?

function foo($a, $b, $c) {
    return bar($a, $b, $c[0], $c[1], $c[2], ..., $c[n]);
}
4
  • function foo($arrParams) is not possible? Commented Nov 17, 2011 at 19:03
  • Yeah, it seems like homework, plus there must be a duplicate question regarding PHP and variable number of function arguments Commented Nov 17, 2011 at 19:04
  • 1
    It's not homework. When I ask questions I remove everything that might confuse the matter. Commented Nov 17, 2011 at 20:14
  • If this is a duplicate please link to the other question so that people can find the other question and vote to close this one. Commented Nov 17, 2011 at 20:17

1 Answer 1

1

call_user_func_array allows you to call a function with an array of parameters. Create the parameter array and call the function:

$parameters = array_merge(array($a, $b), $c);
return call_user_func_array('bar', $parameters);
Sign up to request clarification or add additional context in comments.

1 Comment

Demo of hakre's method with an implementation of bar() and foo().

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.