1
function a($function, $array)
{
    global $test

    $test->$function(implode(',' $array));
}

For example, I want to be able to pass the various arguments to a second function inside.

So if I passed a('x', array('a', 'b')) it'd execute $test->x('a', 'b');

The imploding obviously doesn't work due to making it a string, not passing arguments, unsure how to do it.

0

2 Answers 2

5

You could use call_user_func_array().

call_user_func_array(array($test, $function), $array);
Sign up to request clarification or add additional context in comments.

Comments

0
function a($function, $array)
{
    global $test

    $test->{$function}($array[0], $array[1]);
}

or

function a($function, $arg1, $arg, $arg3...)
{
    global $test
    $arg = func_get_args();
    unset($arg[0]); // because it is the $function arg
    $test->{$function}($arg);
}

1 Comment

Your second alternative takes multiple arguments to a() and passes them as an array to $function. The OP wanted to do the reverse of that.

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.