Answer the question
In order to leave comments, you need to log in
How to form a structure from an xml file?
I may have worded the title wrong, sorry.
The point is this. We have an xml file of 50-70 megabytes. The general structure of the elements is the same, but there are some differences when there are no elements.
I need to create a complete array matrix that will be obtained when fetching this xml.
This is the only diagram that came to mind.
<?php
$xml = simplexml_load_file('pg.xml');
$array = getData($xml);
print_r($array);
function getData($items, $parent = null){
$rgData = [];
if(is_object($items) || is_array($items)){
foreach($items as $key => $item){
$tmp = ((is_array($item)) ? getData($item, $key) : $item);
if(is_numeric($key))
$rgData[$parent] = $tmp;
else
$rgData[$key] = $tmp;
}
return $rgData;
}
return $items;
}
Answer the question
In order to leave comments, you need to log in
Should the attributes be saved?
what prevents to do (array)$xml ?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question