I’m trying to get all categories and push them into my array, so far I’m doing it this way:
$doc = new DOMDocument();
$doc->load('myxml.xml');
$arr = array();
foreach ($doc->getElementsByTagName('item') as $node) {
$items = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('category')->item(0)->nodeValue
);
$arr [] = $items ;
}
This works if we have only 1 cat, however, my xml has several categories per item. What would be a good way of doing this?
<item>
<title>Submit</title>
<category>Foo</category>
<category>Bar</category>
</item>
Thanks
This should help: