Search code examples
phparray-merge

php array_merge looping or similar


Asking for help here, cannot figure it out myself. Need to merge a dynamic number of arrays, but dont know how to loop the array_merge.

Right now it looks like this:

for($i=0;$<$icount;$i++){
$newContent[$i] = array_merge($content[0][$i], $content[1][$i], $content[2][$i], $content[3][$i]);
};// etc.. the numbers keeps growing.

This works, but i have to add arrays manually.

Tryed the answers from the topic of possible duplicate, but nothing gave me the result.


Solution

  • thanks, got it answered on rus stackoverflaw.

    answred

    for($i=0;$<$icount;$i++){
        $newContent[] = call_user_func_array(
            'array_merge',
            array_column($content, $i)
        );
    }