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:
Cake 1.2's Set class eats nested arrays for breakfast!
February 28, 2007 @ 10:04:00

Felix Geisendorfer has a great functionality note that CakePHP users might want to check out. It's related to the Set class and how it handles nested arrays.

So far this has been a little dark spot for me in the core and from my previous quick looks at the class I've never been quite able to figure out what it's exact purpose was. Until now all I knew was "well it's probably some fancy array manipulation code that is somewhat obfuscated and undocumented". Oh boy, I wish I had spent more time on this earlier. It's probably one of coolest new features in 1.2 and nobody realizes it.

He starts with a simple example of how the class works with a nested array of user information. Normally, you'd loop through the array and append the values you'd need to another array (like the user's name), but with Set, it's as simple as calling the static "extract" method with the "path" to what you want out of the array. A simple one-line replacement for a (normally) three to four line bit of code.

He gives a few other examples using this same user information, grabbing various results and includes one at the end that is very nice indeed - pulling in an XML document, running it through a simple xmltoArray function and pulling out the titles in a few easy lines.

0 comments voice your opinion now!
set class cakephp nested array extract combine xml parse set class cakephp nested array extract combine xml parse


blog comments powered by Disqus

Similar Posts

Raphael Stolt's Blog: Setting up Zend Framework applications with Phing

Builder.com: Get the correct time by converting between time zones with PHP and PEAR

Ilia Alshanetsky\'s Blog: PHP 5.1.1 Released! (and a Rant)

Zend Developer Zone: Paging Data Sets With PEAR Pager

Stuart Herbert's Blog: Using SimpleXML To Parse RSS Feeds


Community Events





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


symfony code library introduction list language bugfix developer release threedevsandamaybe application community interview series api podcast install laravel wordpress configure

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