How can I convert an array to a SimpleXML object in PHP?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- Illegal to have multiple roots (start tag in epilo
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
Here is php 5.2 code which will convert array of any depth to xml document:
generated XML would be as:
PHP snippet
Documentation on
SimpleXMLElement::asXML
used in this snippetHere is my entry, simple and clean..
a short one:
results in
keys and values are swapped - you could fix that with
array_flip()
before the array_walk.array_walk_recursive
requires PHP 5. you could usearray_walk
instead, but you won't get'stack' => 'overflow'
in the xml then.From PHP 5.4