-1

I have two arrays, I need to merge both like layer

first array

Array (
      [0]=>1
      [1]=>2
      [2]=>3
     )

Second array

Array (
      [0]=>4
      [1]=>5
      [2]=>6
     )

How to combine it with a result of

Array (
      [0]=>1
      [1]=>2
      [2]=>3
      [3]=>4
      [4]=>5
      [5]=>6

 )

1 Answers1

0

If you don't need to do anything with indexes then the right function is array_merge so in this example:

array_merge($a, $b);

 

Interactive mode enabled

php > $a = [1, 2, 3];
php > $b = [4, 5, 6];
php > print_r(array_merge($a, $b));
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
)
jakub wrona
  • 2,212
  • 17
  • 17