note 104579 deleted from ref.simplexml by danbrown

From: Date: Fri, 24 Jun 2011 15:01:59 +0000
Subject: note 104579 deleted from ref.simplexml by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-180910@lists.php.net to get a copy of this message
Note Submitter: masonswolf [ignorethis] at gmail dot com ---- This is a follow-up based on the same problem k dot antczak was solving - converting a SimpleXMLElement to an associative array. I needed to do the same thing, and came up with a 1-line solution that also works: $array = json_decode(json_encode($xmlObject), true); In addition to being a single line rather than a custom function, it's faster. I benchmarked both approaches with the same SimpleXMLElement (max depth was 3). 50K runs took 2.7s on average using the json hack, while using the xml2array function took 4.8s.

« previous php.notes (#180910) next »