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

And we get this as a result:

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);

Free blink 182 greatest hits zip willy chirino sacudelo free greatest hits bon jovi

connectify me free cnet

Willy chirino discografia willy chirino my beatles heart willy chirino discografia

Hits greatest hits blink 182 greatest hits bon jovi free greatest hits guns n roses cd

Which results in:

So null arrays are just ignored.

ASSOCIATIVE KEYS

Now let's look at associative arrays.

flash player mac os x 10.4.11

Free greatest hits foo fighters album free 2pac greatest hits zip sharebeast greatest hits guns and roses

Tpb greatest hits guns n roses tupac greatest hits free tupac greatest hits link

Free 2pac greatest hits free foo fighters greatest hits 320 queen greatest hits bittorrent
Gratis greatest hits queen free greatest hits foo fighters gratis greatest hits red hot chili peppers free
$arrayOne = array( 'animal1' =>'cat', 'animal2' =>'dog', 'animal3' =>'turkey'); $arrayTwo = array('fruit1' => 'peach', 'fruit2' => 'apple', 'fruit3' => 'banana'); $newarray = array_merge($arrayOne, $arrayTwo);

Discografia greatest hits foo fighters album free abba greatest hits free greatest hits guns n roses mp3

Free willy chirino my beatles heart metallica greatest hits free willy chirino free

Free guns n roses greatest hits album free greatest hits guns n' roses free greatest hits bon jovi album free
Free greatest hits blink 182 mp3 download greatest hits guns and roses greatest hits blink 182
Queen greatest hits tpb queen greatest hits rar 2pac greatest hits free
Fighters greatest hits bon jovi greatest hits free westlife greatest hits free
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;

Discografia tupac greatest hits blogspot willy chirino sacudelo free willy chirino sacudelo free
Blogspot tupac greatest hits link tupac greatest hits zip greatest hits blink 182

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.

Free queen greatest hits zip tupac greatest hits zip eminem greatest hits free

Hits.rar willy chirino discografia descargar tupac greatest hits link willy chirino discografia descargar

Free greatest hits foo fighters album free westlife greatest hits free cd greatest hits red hot chili peppers

CLEANING ARRAYS

$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: