How to remove SimpleXMLElement Object from php array

拥有回忆 提交于 2019-12-03 21:16:45

this will give you a simple associative array:

$array = json_decode(json_encode($xml), true);

I have solved my problem using below code.

function simplexml_to_array($xmlobj) {
    $a = array();
    foreach ($xmlobj->children() as $node) {
        if (is_array($node))
            $a[$node->getName()] = simplexml_to_array($node);
        else
            $a[$node->getName()] = (string) $node;
    }
    return $a;
} 


foreach($xml->children() as $child)
{
    $arr=simplexml_to_array($child );
    echo "<pre>".html_entity_decode(print_r($arr,true))."</pre>";
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!