SimpleXML Attributes to Array

前端 未结 5 1018
臣服心动
臣服心动 2020-12-15 05:19

Is there any more elegant way to escape SimpleXML attributes to an array?

$result = $xml->xpath( $xpath );
$element = $result[ 0 ];
$attributes = (array)          


        
5条回答
  •  情书的邮戳
    2020-12-15 05:30

    You could convert the whole xml document into an array:

    $array = json_decode(json_encode((array) simplexml_load_string("{$xml}")), true);
    

    For more information see: https://github.com/gaarf/XML-string-to-PHP-array

提交回复
热议问题