title: how to parse xml file using simplexml and create multidimensional array in PHP
body: <p>I am trying to parse a xml file as below to create a  multidimensional array .</p>
  
  <pre><code> &lt;workbook  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" &gt;
  &lt;Worksheet ss:Name="45"&gt;
    &lt;Table&gt;
         &lt;Row&gt;&lt;Cell&gt;&lt;Data&gt;232&lt;/Data&gt;&lt;/Cell&gt;&lt;/Row&gt;
     &lt;Row&gt;&lt;Cell&gt;&lt;Data&gt;Apple&lt;/Data&gt;&lt;/Cell&gt;&lt;/Row&gt;
    &lt;/Table&gt;
  &lt;/Worksheet&gt;
  &lt;Worksheet ss:Name="46 - new"&gt;
    &lt;Table&gt;
         &lt;Row&gt;&lt;Cell&gt;&lt;Data&gt;876&lt;/Data&gt;&lt;/Cell&gt;&lt;/Row&gt;
     &lt;Row&gt;&lt;Cell&gt;&lt;Data&gt;samsung&lt;/Data&gt;&lt;/Cell&gt;&lt;/Row&gt;
     &lt;/Table&gt;
  &lt;/Worksheet&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here is the code thus far.</p>
  
  <pre><code>$xml=simplexml_load_file($xmlfile);
  $result= array();
  foreach($xml-&gt;Worksheet as $worksheet ) {
    $result['tab']['name'][]=$worksheet-&gt;attributes('ss', TRUE)-&gt;Name;
    foreach($worksheet as $table){
      foreach($table as $row){
        foreach($row as  $cell){
          $result['tab']['units'][]=$cell-&gt;Data;
        }
      }
    }
  }
  
  print_r($result);
  </code></pre>
  
  <p>I am trying to get array as below :</p>
  
  <pre><code>items =[
     tab=&gt;[
     'name' =&gt; '45',
     'units'=&gt;[
        ['0'=&gt;'232'],
        ['1'=&gt;'Apple']
     ]
     ]
     tab=&gt;[
     'name' =&gt; '46-new',
     'units'=&gt;[
        ['0'=&gt;'876'],
        ['1'=&gt;'samsung']
     ]
     ]
   ];
  </code></pre>
  
  <p>but i'm getting the result  as below .</p>
  
  <pre><code>array(
      [tab]=&gt;array(
         [name]=&gt;array
         (
            [0]=&gt;SimpleXmlElement Object
             ( 
               [0]=&gt; 45
             )
            [1]=&gt;SimpleXmlElement object
             ( 
               [1]=&gt;46-new
             )
         )
         [units]=&gt;array
         (
            [0]=&gt;SimpleXmlElement Object
             ( 
               [0]=&gt; Nr
             )
            [1]=&gt;SimpleXmlElement object
             ( 
               [0]=&gt;model
             )
             [2]=&gt;SimpleXmlElement Object
             ( 
               [0]=&gt; 232
             )
            [3]=&gt;SimpleXmlElement object
             ( 
               [0]=&gt;apple
             ) 
             .........
         )
  
      )
  )
  </code></pre>
  
  <p>it's quite challenging .How should the code be modified to achieve the goal?</p>