I have this code:
$dom = new DOMDocument(); $dom->load('file.xml'); $names = $dom->getElementsByTagName('name');
Now, $names
is DOMNodeList object, I need to convert this object into an array,
$names = (array)$names; var_dump($names); // empty array
The above code does not work and returns an empty array, why?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With