title: PHP/SimpleXML - Arrays generated differently for single child and multiple children
body: <p>I'm using SimpleXML to parse an XML feed of property listings from different realtors. The relevant section of the XML feed looks something like this:</p>
  
  <pre><code>&lt;branch name="Trustee Realtors"&gt;
      &lt;properties&gt;
          &lt;property&gt;
              &lt;reference&gt;1&lt;/reference&gt;
              &lt;price&gt;275000&lt;/price&gt;
              &lt;bedrooms&gt;3&lt;/bedrooms&gt;
          &lt;/property&gt;
          &lt;property&gt;
              &lt;reference&gt;2&lt;/reference&gt;
              &lt;price&gt;350000&lt;/price&gt;
              &lt;bedrooms&gt;4&lt;/bedrooms&gt;
          &lt;/property&gt;
          &lt;property&gt;
              &lt;reference&gt;3&lt;/reference&gt;
              &lt;price&gt;128500&lt;/price&gt;
              &lt;bedrooms&gt;4&lt;/bedrooms&gt;
          &lt;/property&gt;
      &lt;/properties&gt;
  &lt;/branch&gt;
  &lt;branch name="Quick-E-Realty Inc"&gt;
      &lt;properties&gt;
          &lt;property&gt;
              &lt;reference&gt;4&lt;/reference&gt;
              &lt;price&gt;180995&lt;/price&gt;
              &lt;bedrooms&gt;3&lt;/bedrooms&gt;
          &lt;/property&gt;
      &lt;/properties&gt;
  &lt;/branch&gt;
  </code></pre>
  
  <p>and is then converted to an array like this:</p>
  
  <pre><code>$xml = file_get_contents($filename);
  $xml = simplexml_load_string($xml);
  $xml_array = json_decode(json_encode((array) $xml), 1);
  $xml_array = array($xml-&gt;getName() =&gt; $xml_array);
  </code></pre>
  
  <p>The issue I'm having is that when the array is created the data for the single listing is in a different position in the array to the multiple listings - I'm not sure exactly how to explain this, but if I var_dump() the array for the multiple items it looks like this:</p>
  
  <pre><code>array(3) {
      [0]=&gt;
      array(3) {
          ["reference"]=&gt;
          string(4) "0001"
          ["price"]=&gt;
          string(6) "275000"
          ["bedrooms"]=&gt;
          int(3)
      }
      [1]=&gt;
      array(3) {
          ["reference"]=&gt;
          string(4) "0002"
          ["price"]=&gt;
          string(6) "350000"
          ["bedrooms"]=&gt;
          int(4)
      }
      [2]=&gt;
      array(3) {
      ["reference"]=&gt;
          string(4) "0003"
          ["price"]=&gt;
          string(6) "128500"
          ["bedrooms"]=&gt;
          int(2)
      }
  }
  </code></pre>
  
  <p>If I var_dump() the array for the single listing it looks like this:</p>
  
  <pre><code>array(3) {
      ["reference"]=&gt;
      string(4) "0004"
      ["price"]=&gt;
      string(6) "180995"
      ["bedrooms"]=&gt;
      int(3)
  }
  </code></pre>
  
  <p>But what I need it to look like is this:</p>
  
  <pre><code>array(1) {
      [0]=&gt;
      array(3) {
          ["reference"]=&gt;
          string(4) "0004"
          ["price"]=&gt;
          string(6) "180995"
          ["bedrooms"]=&gt;
          int(3)
      }
  }
  </code></pre>
  
  <p>Each of these arrays represents the property listings from a single realtor. I'm not sure whether this is just the way that SimpleXML or the json functions work but what I need is for the same format to be used (the array containing the property listing to be the value of the [0] key).</p>
  
  <p>Thanks in advance!</p>