Daily Archives: Friday 03/09/2010

PHP: Merge Two Arrays but Keep Their Keys Intact CodeUnit 03 SEP 2010

Combining two or more arrays whilst keeping their keys intact in PHP is deceptively simple – though not if you assume you need to use a function like array_merge to achieve this!

As you scroll through the various array functions available to you, you will notice that quite a few seem to drop the array keys after they are done, which is pretty useless if all you want to do is basically add two arrays to one another to form one big keyed array.

So how do you do this then?

Simple really. Just literally add them together!

$resultarr = $array1 + $array2;

And just in case you are wondering what the hell is going on, remember that when applied to arrays, the + acts as a union operator.

Nice!

Photo Gallery: Laying the Drainage Chips (2010-09-03) My Life | Photo Gallery 03 SEP 2010

I played around a lot with the layout of our little driveway. One thing I was certain of however, was that I was definitely going to be replacing a lot of those ugly cement slabs with drainage chips.

[subvertedgallery link=”file” columns=”4″ orderby=”post_date”]