0

Question may be confusing...

the php array_merge() function takes an unlimited amount of arguments E.G.

array_merge($array1, $array2, $array3, $array4, $array5, $array6, $array7);

but what if I want to call this from within a function?

I have a merge() function that can be overloaded, and I want to do things to the array before concatenating them!

so how is array_merge called when I've got the array arguments in an array?

EXAMPLE

public function index() {

    $head = $this->_model->title("Index Page"); // returns array

    $nav = $this->_model->navigation(); // returns array

    $default = $this->_model->default_page(); // returns array

    $data = $this->merge($head, $nav, $default); // merge all arrays

    $this->loadView( 'view_admin', $data );
}

private function merge(){
    $args = func_get_args();

    // ... do stuff the the arrays ...

    return array_merge($args[0],$args[1],$args[2]);
}

As you can see, currently in my merge function is:

return array_merge($args[0],$args[1],$args[2]);

This is hardcoded in.

How do I dynamically call the array_merge() function???

maybe something like

array_merge(/* All Array args passed in */) 

2 Answers 2

3
return call_user_func_array('array_merge', $args);
Sign up to request clarification or add additional context in comments.

Comments

1

You could probably use call_user_func (http://php.net/manual/en/function.call-user-func.php) as:

return call_user_func("array_merge", $args);

Comments

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.