title: Using DOMDOcument in PHP to parse XML and return an array of tree structure
body: <p>I am very sorry if my question doesn't make sense as this is my first question, however i've been going through the questions posted for a while now.</p>
  
  <p>right i have a XML structure of</p>
  
  <pre><code>&lt;category&gt;
    &lt;id&gt;123456&lt;/id&gt;
    &lt;name&gt;Sales&lt;/name&gt;
  &lt;categories&gt;
    &lt;category&gt;
      &lt;id&gt;2345&lt;/id&gt;
      &lt;name&gt;UK House prices&lt;/name&gt;
    &lt;/category&gt;
    &lt;category&gt;
      &lt;id&gt;3456&lt;/id&gt;
      &lt;name&gt;Property Market Surveys&lt;/name&gt;
    &lt;/category&gt;
  &lt;/categories&gt;
  </code></pre>
  
  <p></p>
  
  <p>I'd want a function to parse through the above xml and generate an array idealy to look something like this</p>
  
  <pre><code>array(
    "123456" =&gt; 
    array(
      "id" =&gt; "2345",
      "name" =&gt; "UK House prces",
    ),
    array(
      "id" =&gt; "3456",
      "name" =&gt; "Property Market Surveys",
    )
  );
  </code></pre>
  
  <p>i must then be able to extract data of the array and insert it into a table with parent child relation.</p>
  
  <p>Please let me know if you need more info to make this question complete.</p>
  
  <p>Thanks a lot for your time.</p>
  
  <p>Regards.</p>