$arrayOne = array('cat', 'dog', 'turkey');
$arrayTwo = array('peach', 'apple', 'banana');
foreach ($arrayTwo as $aRow) {
    $arrayOne[] = $aRow;
}

And we get this as a result:

1 windows 2008 r2 download sp1 windows 2008 sp2 ntbackup.exe for windows 2008

Trial windows 2008 iso enterprise windows 2008 service pack windows server 2008 microsoft

Simple, but why do that when you can do this in one line using array_merge:

$newarray = array_merge($arrayOne, $arrayTwo);

and get this:

Array merge works with two or more arrays. Let's do it:

$arrayOne = array('cat', 'dog', 'turkey');
$arrayTwo = array('peach', 'apple', 'banana');
$arrayThree = array('dodge', 'ford', 'mazda');
$threeArrays = array_merge($arrayOne, $arrayTwo, $arrayThree);
new chk ($threeArrays);

And we get this:

As you can see newchk is easy to use, and you get great results. Let's get back to array_merge.

NULL ARRAYS

What if one of the arrays was a null?

$arrayOne = array('cat', 'dog', 'turkey');
$arrayTwo = array();
$arrayThree = array('dodge', 'ford', 'mazda');
$arrayNull = array_merge($arrayOne, $arrayTwo, $arrayThree);

Which results in:

So null arrays are just ignored.

ASSOCIATIVE KEYS

Now let's look at associative arrays.

$arrayOne = array( 'animal1' =>'cat', 'animal2' =>'dog', 'animal3' =>'turkey');
$arrayTwo = array('fruit1' => 'peach', 'fruit2' => 'apple', 'fruit3' => 'banana');
$newarray = array_merge($arrayOne, $arrayTwo);

What we expect:

But what if we had the same key in each of arrays?

$arrayOne = array( 'animal1' =>'cat', 'sameKey' =>'dog', 'animal3' =>'turkey');
$arrayTwo = array('fruit1' => 'peach', 'sameKey' => 'apple', 'fruit3' => 'banana');
$arrayThree = array( 'car1' => 'dodge', 'sameKey' => 'ford', 'car3' => 'mazda');
$newArr = array_merge($arrayOne, $arrayTwo, $arrayThree);

What I've done is put the same associative key in each array, and here are the results;

Version windows server 2008 free microsoft windows 2008 sp1 r2 windows 2008 sp2

Bit windows 2008 r2 trial iso windows 2008 sbs trial windows 2008r2 evaluation

Iso windows server 2008 r2 32 bit windows 2008 iso microsoft windows 2008 r2 sp2 trial

Bit windows 2008 r2 microsoft windows 2008 enterprise edition iso windows server 2008 r2 microsoft

Sp1 windows 2008 enterprise edition iso ntbackup.exe for windows 2008 windows 2008 r2 enterprise iso

Sp1 windows 2008 r2 enterprise iso microsoft windows 2008 trial windows 2008 evaluation

Trial windows 2008 evaluation windows 2008 r2 crack windows server 2008 r2 enterprise edition iso

Iso windows 2008 sp1 x64 windows 2008 r2 iso windows 2008 r2 microsoft


Bit windows 2008 r2 full windows 2008 r2 sp2 trial windows 2008 sp2 64 bit
Iso windows 2008 r2 trial download iso windows 2008 standard evaluation ntbackup.exe for server 2008

Iso windows server 2008 evaluation microsoft windows 2008 free windows 2008 r2 free
Microsoft windows 2008 sp1 r2 windows powershell 2008 32 bit windows 2008 r2 sp1 32 bit

NUMERIC KEYS

What if we used intergers for keys, would we get the same results?

$arrayOne = array( 0 =>'cat', 2 =>'dog', 4 =>'turkey');
$arrayTwo = array( 0 => 'peach', 2  => 'apple', 4 => 'banana');
$newArr = array_merge($arrayOne, $arrayTwo);

ARRAY UNION

$arrayOne = array( 0 =>'cat', 2 =>'dog', 4 =>'turkey');
$arrayTwo = array( 0 => 'peach', 2  => 'apple', 4 => 'banana');
$unionArr =  $arrayOne +  $arrayTwo;

And we get:

Notice that the keys that are the same are ignored in the second array.

STRINGS

$arrayOne = 'The quick fox blew it by not turning this into an array";
$arrayTwo = array( 0 => 'peach', 2  => 'apple', 4 => 'banana');
$stringArr =  array_merge( $arrayOne , $arrayTwo);
new chk( $arrayOne, $arrayTwo , $stringMerge );

$arrayOne =  (array) 'The quick fox blew it by not turning this into an array";
$arrayTwo = array( 0 => 'peach', 2  => 'apple', 4 => 'banana');
$stringMerge =  array_merge( $arrayOne , $arrayTwo);
new chk( $arrayOne, $arrayTwo , $stringMerge );

And we get:

Now that we cast the string as an array, array_merge works as expected.

CLEANING ARRAYS

Microsoft windows 2008 32 bit windows 2008 r2 windows 2008 microsoft

Evaluation windows server 2008 sp1 windows server enterprise 2008 iso windows 2008 r2 microsoft

Trial windows 2008 sp1 r2 windows 2008 r2 full windows 2008 service pack 1
R2 windows 2008 trial windows 2008 r2 sp1 iso windows server 2008 trial version

Trial windows 2008 r2 trial iso windows 2008 sbs trial windows server 2008 enterprise x64 iso

Evaluation windows server 2008 microsoft windows 2008 r2 sp1 windows server 2008 enterprise edition iso
$arrayOne = array( 'animal1' =>'cat', 'animal2' =>'dog', 'animal3' =>'turkey'); $arrayTwo = array('fruit1' => '', 'sameKey' => '', 'fruit3' => 'banana'); $arrayThree = array( 'animal4' => 'cat', 'animal5' => 'lion', 'animal6' => 'turkey');

$uniqueArr = array_unique($mergeArr);
$filterArr = array_filter($uniqueArr);

And here are the last two arrays: