1

I have an array like this:

Array
(
    [0] => wahyu@email.co.id
    [1] => wahyu@email.co.id
)
Array
(
    [0] => wahyu@email.co.id
    [1] => wahyu@email.co.id
)

I would like to combine array above like this:

Array
(
    [0] => wahyu@email.co.id
    [1] => wahyu@email.co.id
    [2] => wahyu@email.co.id
    [3] => wahyu@email.co.id
)

How the way to combine it?

7 Answers7

2

array_merge function is used for the combine two array.

$a = array("0" => "one@email.co.id",
    "1" => "two@email.co.id"
);

$b = array(
    "0" => "three@email.co.id",
    "1" => "four@email.co.id"
);


$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 = ['wahyu@email.co.id', 'wahyu@email.co.id'];
$arr2 = ['wahyu@email.co.id', 'wahyu@email.co.id'];
$arr3 = array_merge($arr1, arr2);
Kamal Paliwal
  • 1,251
  • 8
  • 16
0

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

<?php
$a1=array("wahyu@email.co.id","wahyu@email.co.id");
$a2=array("wahyu@email.co.id","wahyu@email.co.id");
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@domain.com","email2@domain.com");
$array2 = array("email3@domain.com","email4@domain.com");

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

Here is what you are looking for,

$array1 = [
    0 => 'wahyu@email.co.id',
    1 => 'wahyu@email.co.id',
];
$array2 = [
    0 => 'wahyu@email.co.id',
    1 => 'wahyu@email.co.id',
];
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] => wahyu@email.co.id
    [1] => wahyu@email.co.id
    [2] => wahyu@email.co.id
    [3] => wahyu@email.co.id
)

Demo.

Rahul
  • 18,271
  • 7
  • 41
  • 60