How to convert DOMNodeList object into array

后端 未结 5 524
春和景丽
春和景丽 2021-01-03 22:58

I have this code:

     $dom = new DOMDocument();
     $dom->load(\'file.xml\');
     $names = $dom->getElementsByTagName(\'name\');

N

5条回答
  •  花落未央
    2021-01-03 23:38

    Use iterator_to_array() to convert a DomNodeList to an Array

    $document = new DomDocument();
    $document->load('test.xrds');
    $nodeList = $document->getElementsByTagName('Type');
    $array = iterator_to_array($nodeList);
    

提交回复
热议问题