1

I have an array like this:

Array
(
    [0] => [email protected]
    [1] => [email protected]
)
Array
(
    [0] => [email protected]
    [1] => [email protected]
)

I would like to combine array above like this:

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

How the way to combine it?

7 Answers7

2

array_merge function is used for the combine two array.

$a = array("0" => "[email protected]",
    "1" => "[email protected]"
);

$b = array(
    "0" => "[email protected]",
    "1" => "[email protected]"
);


$merged_array = array_merge($a,$b);

echo "<prE>";
print_r($merged_array);
Rohan Varma
  • 101
  • 7
0

use array_merge(arr_1,arr_2,arr_3) function to merge two or more arrays.

Shivam Arora
  • 354
  • 2
  • 8
0

You can use array_merge to combine both arrays like this:

$arr1 = ['[email protected]', '[email protected]'];
$arr2 = ['[email protected]', '[email protected]'];
$arr3 = array_merge($arr1, arr2);
Kamal Paliwal
  • 1,251
  • 8
  • 16
0

=> Try array_merge() Function to merge two array.

<?php
$a1=array("[email protected]","[email protected]");
$a2=array("[email protected]","[email protected]");
print_r(array_merge($a1,$a2));
?>

Demo:- https://paiza.io/projects/5-7Cdo5GIMenayUP0cIDGg

Nimesh Patel
  • 796
  • 1
  • 7
  • 23
0

You can achieve like this way.

PHP has built-in function array_merge.

For example:

$newArray = array_merge($array1, $array2);
Naveed Ramzan
  • 3,565
  • 3
  • 25
  • 30
0

Use the PHP array_merge...

Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one.

see docs: http://php.net/manual/en/function.array-merge.php

<?php
$array1 = array("[email protected]","[email protected]");
$array2 = array("[email protected]","[email protected]");

$array_merged = array_merge($array1, $array2);
?>
caiovisk
  • 3,667
  • 1
  • 12
  • 18
0

Here is what you are looking for,

$array1 = [
    0 => '[email protected]',
    1 => '[email protected]',
];
$array2 = [
    0 => '[email protected]',
    1 => '[email protected]',
];
array_splice($array1, count($array1), 0, $array2);
print_r($array1);

array_splice — Remove a portion of the array and replace it with something else

Output:

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

Demo.

Rahul
  • 18,271
  • 7
  • 41
  • 60