B
B
borg7472017-10-01 19:54:40
PHP
borg747, 2017-10-01 19:54:40

How can you merge 3D arrays?

Good evening. There are two arrays:
$arr1 = array(
array( 3 , array (6, 7, 8 )),
array( 6 , array (5, 6, 8 )),
array( 15 , array (5, 12, 13 )) ,
array( 16 , array (2, 3, 21, 22 ))
);
$arr2 = array(
array( 1 , array ( 9, 15 )),
array( 6 , array ( 7 ))
);
It is necessary to combine them, leaving the data from the first and adding from the second.
$arr3_result= array(
array( 1 , array ( 9, 15 )),
array( 3 , array (6, 7, 8 )),
array( 6 , array (5, 6, 7, 8 )),
array( 15 , array (5, 12, 13 )),
array( 16 , array (2, 3, 21, 22 ))
);
How can they be combined like that? I drew schemes for iterating through foreach, but it turns out so cumbersome that I myself can’t figure it out later in this garden.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2017-10-01
@borg747

php.net/manual/en/function.array-merge-recursive.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question