News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Felix Geisendorfer's Blog:
New fix for array junkies Setmerge assembles yummy arrays
April 06, 2007 @ 09:29:00

In a new post today, Felix Geisendorfer shares a method for merging together nested arrays correctly with a little help from functionality in the CakePHP framework.

Todays post features a brand new Set function called merge that was a side product of me working on a cool new cake class. If you've done a lot of array work in the past, you've probably have come in situations where you wanted to merge to arrays into a new one. Usually that's a no-brainer in PHP by simply using the array_merge function (or the CakePHP wrapper 'am'):

In about 90%++ of all cases, this will the usual way to merge two (or more) arrays into a new one. However, sometimes array_merge is not going to cut it. That'll mostly be because it does not behave recursive and merging nested arrays can lead to unexpected results.

He even shows an example of the use of array_merge_recursive to try to get his desired results. With that still not working, he turns to CakePHP to help him out. He comes up with the Set::merge method to handle the merging of the arrays in what he thinks is a "more correct" way.

0 comments voice your opinion now!
merge array arraymerge arraymergerecursive cakephpframework merge array arraymerge arraymergerecursive cakephpframework


blog comments powered by Disqus

Similar Posts

SitePoint: Build a Photo Gallery Using CakePHP and Flickr

The Bakery: 11 New Posts of CakePHP Goodness

Pawel Turlejski's Blo: What's wrong with PHP closures?

Lorna Mitchell's Blog: Using iterator_to_array() in PHP

Felix Geisendorfer's Blog: New fix for array junkies: Set::merge assembles yummy arrays


Community Events





Don't see your event here?
Let us know!


framework release bugfix conference language deployment tips zendserver threedevsandamaybe laravel voicesoftheelephpant interview introduction series symfony code api podcast community list

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework