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);
$Xml->toArray();

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…

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

Pretty cool.

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

Related Posts

%d bloggers like this: