note 104579 added to ref.simplexml
| From: | masonswolf | Date: | Thu, 23 Jun 2011 20:20:15 +0000 |
| Subject: | note 104579 added to ref.simplexml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-180902@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 69.147.83.197
Probable Submitter: 12.169.97.130
----
Manual Page -- http://www.php.net/manual/en/ref.simplexml.php
Edit -- https://master.php.net/note/edit/104579
Del: integrated -- https://master.php.net/note/delete/104579/integrated
Del: useless -- https://master.php.net/note/delete/104579/useless
Del: bad code -- https://master.php.net/note/delete/104579/bad+code
Del: spam -- https://master.php.net/note/delete/104579/spam
Del: non-english -- https://master.php.net/note/delete/104579/non-english
Del: in docs -- https://master.php.net/note/delete/104579/in+docs
Del: other reasons-- https://master.php.net/note/delete/104579
Reject -- https://master.php.net/note/reject/104579
Search -- https://master.php.net/manage/user-notes.php