title: Php parse multilevel - xml into array
body: <p>I am trying to convert xml into php array but somehow i am doing a mistake, can anyone please help me ?</p>
  
  <p>Here the xml formate : </p>
  
  <pre><code>&lt;Department Id="3"&gt;
      &lt;Week Date="23/03/2020"&gt;
          &lt;Class DateTime="23/03/2020 18:00"/&gt;
          &lt;Class DateTime="23/03/2020 18:45"/&gt;
      &lt;/Week&gt;
      &lt;Week Date="30/03/2020"&gt;
          &lt;Class DateTime="30/03/2020 18:00"/&gt;
          &lt;Class DateTime="30/03/2020 18:45"/&gt;
      &lt;/Week&gt;
  &lt;/Department&gt;
  </code></pre>
  
  <p>Output Need like this :</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [DateTime] =&gt; 23/03/2020 18:00
                  )
              [1] =&gt; Array
                  (
                      [DateTime] =&gt; 23/03/2020 18:45
                  )
          )
      [1] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [DateTime] =&gt; 30/03/2020 18:00
                  )
              [1] =&gt; Array
                  (
                      [DateTime] =&gt; 30/03/2020 18:45
                  )
          )   
  )
  </code></pre>
  
  <p>This is what i have tried </p>
  
  <pre><code>foreach ($xml-&gt;children() as $week) {
      foreach ($week-&gt;children() as $class) {
          $j = 0;
          foreach ($class-&gt;attributes() as $a =&gt; $b){
              $results[$i][$j][$a] = (string) $b;
          }
          $j++;
      }
      $i++;
  }
  </code></pre>
  
  <p>I dont know whats wrong in my code :(</p>