Array from XML in CakePHP

Update (9/9/2008): Since the writing of this post, there is now a nicer way to handle this, which David Persson kindly pointed out:

$Xml = new Xml($rawXML);

For historical reference and if you don’t have the latest and greatest CakePHP core, here’s the “old method”…

On IRC gwoo posted a neat trick to convert an XML string into an array.
I thought that it definitely deserves to be shared with everyone…

$myArray = Set::reverse(new Xml(… your XML here…));

Pretty cool.

P.S. Be sure to include: uses(‘Xml’);

%d bloggers like this: