Convert a SimpleXML object to an associative array

原文地址:https://gist.github.com/jasondmoss/7344311
<?php /** * Convert a SimpleXML object to an associative array * * @param object $xmlObject * * @return array * @access public */ function simpleXmlToArray($xmlObject) { $array = []; foreach ($xmlObject->children() as $node) { $array[$node->getName()] = is_array($node) ? simplexml_to_array($node) : (string) $node; } return $array; }

2、或者直接

(array)xmlObject

posted on 2019-05-07 14:17  ZhYQ_note  阅读(57)  评论(0)    收藏  举报

导航