note 63583 deleted from ref.simplexml by bjori
| From: | bjori@php.net | Date: | Fri, 24 Mar 2006 19:38:34 +0000 |
| Subject: | note 63583 deleted from ref.simplexml by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-106549@lists.php.net to get a copy of this message | ||
Note Submitter: romain dot lalaut at laposte dot net
Reason: bad code
----
Another function that convert SimpleXMLElement to array.
I hope this will be useful...
<?php
/**
* Convert SimpleXMLElement object to array
* Copyleft GPL license
* @author Romain Lalaut 2006
*
* @param SimpleXMLElement
* @return array
*/
function simplexml2array(SimpleXMLElement &$xml)
{
$result = array();
$attributes = $xml->attributes();
foreach($attributes as $aname=>$avalue)
$result['@attrs'][$aname] = (string) $avalue;
$value = (string) $xml;
if($value)
$result['@value'] = $value;
$children = $xml->children();
foreach($children as $cname=>$cnode)
$result[$cname] = simplexml2array($cnode);
return $result;
}
?>