title: XML to PHP array when simpleXML isn't acurate
body: <p>Ok so i have a problem where i am pulling data base from an API and the structure is returned as below:</p>
  
  <pre><code>&lt;Response id="responceidgoeshere"&gt;
    &lt;block name="addresses"&gt;
      &lt;block&gt;
        &lt;a name="building" format="text"&gt;#NAME/NUM#&lt;/a&gt;
        &lt;a name="sub-premise" format="text"&gt;#SUB-PREM#&lt;/a&gt;
        &lt;a name="street" format="text"&gt;#STREET#&lt;/a&gt;
        &lt;a name="locality" format="text"&gt;#LOCAL#&lt;/a&gt;
        &lt;a name="city" format="text"&gt;#CITY#&lt;/a&gt;
        &lt;a name="postcode" format="text"&gt;#POSTCODE#&lt;/a&gt;
        &lt;a name="ref" format="text"&gt;#REF#&lt;/a&gt;
        &lt;a name="csscode" format="text"&gt;#CSS#&lt;/a&gt;
      &lt;/block&gt;
      &lt;block&gt;
        &lt;a name="building" format="text"&gt;#NAME/NUM#&lt;/a&gt;
        &lt;a name="street" format="text"&gt;#STREET#&lt;/a&gt;
        &lt;a name="locality" format="text"&gt;#LOCAL#&lt;/a&gt;
        &lt;a name="city" format="text"&gt;#CITY#&lt;/a&gt;
        &lt;a name="postcode" format="text"&gt;#POSTCODE#&lt;/a&gt;
        &lt;a name="ref" format="text"/&gt;
        &lt;a name="csscode" format="text"/&gt;
      &lt;/block&gt;
      &lt;/block&gt;
  &lt;/Response&gt;
  </code></pre>
  
  <p>However, you can see the data changes slightly between results depending on the address. 
  When i use simpleXML to convert to PHP array i end up with the following:</p>
  
  <p>EDIT: including conversion method:</p>
  
  <pre><code>$xml=simplexml_load_string($result, "SimpleXMLElement", LIBXML_NOCDATA);
  $json=json_encode($xml);
  $array=json_decode($json,TRUE);
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>[0] =&gt; Array
      (
          [a] =&gt; Array
              (
                  [0] =&gt; #NAME/NUM#
                  [1] =&gt; #SUB-PREM#
                  [2] =&gt; #STREET#
                  [3] =&gt; #LOCAL#
                  [4] =&gt; #CITY#
                  [5] =&gt; #POSTCODE#
                  [6] =&gt; #REF#
                  [7] =&gt; #CSS#
              )
      [1] =&gt; Array
      (
          [a] =&gt; Array
              (
                  [0] =&gt; #NAME/NUM#
                  [1] =&gt; #STREET#
                  [2] =&gt; #LOCAL#
                  [3] =&gt; #CITY#
                  [4] =&gt; #POSTCODE#
                  [5] =&gt; #REF#
                  [6] =&gt; #CSS#
              )
  </code></pre>
  
  <p>I ideally need a way to create a PHP array with the "name" attr as the key. Does anyone know the best way to do this as the standard simpleXML is too inconsitent for what i need as there wont always be a sub premice element and sometimes there will be a county element too.</p>
  
  <p>EDIT: Example of desired structure:</p>
  
  <pre><code>[0]=array
  (
     [a]=array
     (
         ['building'] =&gt; #NAME/NUM#,
         ['sub-premise'] =&gt; #SUB-PREM#,
         ['street'] =&gt; #STREET#,
         etc...
     )
  )
  </code></pre>