I’m really stucked and don’t know how to implement an idea better. So, we have an XML file:

I’ve got an array by function dom_to_array()
function dom2array($node) {$result = array();
if($node->nodeType == XML_TEXT_NODE) {
$result = $node->nodeValue;
}
else {
if($node->hasAttributes()) {
$attributes = $node->attributes;
if(!is_null($attributes))
foreach ($attributes as $index=>$attr)
$result[$attr->name] = $attr->value;
}
if($node->hasChildNodes()){
$children = $node->childNodes;
for($i=0;$i<$children->length;$i++) {
$child = $children->item($i);
if($child->nodeName != '#text')
if(!isset($result[$child->nodeName]))
$result[$child->nodeName] = $this->dom2array($child);
else {
$aux = $result[$child->nodeName];
$result[$child->nodeName] = array( $aux );
$result[$child->nodeName][] = $this->dom2array($child);
}
}
}
}
return $result;
}
I’ve got an array with first XML element – STRUCTURE.
Array
–STRUCTURE
—-PAGE
—-PAGE
— — –PAGE
—-PAGE
So the main question is how make array looks like this:
Array
—-PAGE
—-PAGE
— — –PAGE
—-PAGE
How to do it better friends – i don’t need to include “structure” into array, is it possible to create by DOM functions ?!
Basically you just want to exclude the
structurelevel from the created PHP array?I guess, you do something like this right now:
The resulting array includes the
structurekey.What you can do is start from the structure element like so:
Or you leave it as is and do it this way using the array key: