Order of ARRAY not maintained after converting XML to ARRAY in PHP
<p>After using the simplexml_file_load in PHP I tried to use some code (XmlToArray()) I found in Php.NET(http://www.php.net/manual/en/ref.simplexml.php) to convert the xml to an array so that I can process the response and then do a post it to a given URL.</p>

<p>However, the order that was defined in the XML doc is NOT how the array was displayed in my terminal when I did a print_r(array).</p>

<p>Is there a way to maintain the same order that is listed in the XML in the array?  Any help/direction would be appreciated.</p>

<p>Here is the xml as it is local to my machine:</p>

<pre><code>    &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
&lt;order xmlns="http://www.shutterfly.com/orderv2/order"&gt;
    &lt;version&gt;2.0&lt;/version&gt;
    &lt;orderNo&gt;sfly.000020513524-7001536_28935-tb.33&lt;/orderNo&gt;
    &lt;orderDate&gt;2012-09-21 09:52:53 PDT&lt;/orderDate&gt;
    &lt;processing&gt;
        &lt;statusCallback&gt;http://orderfulfillment.shutterfly.com/ogateway-test/status/sfly/xpressdocs/
        &lt;/statusCallback&gt;
    &lt;/processing&gt;
    &lt;suborders&gt;
        &lt;suborder&gt;
            &lt;suborderNo&gt;51917&lt;/suborderNo&gt;
            &lt;deliveryEstimate&gt;
                &lt;earliest&gt;2012-10-01 00:00:00 PDT&lt;/earliest&gt;
                &lt;latest&gt;2012-10-05 00:00:00 PDT&lt;/latest&gt;
            &lt;/deliveryEstimate&gt;
            &lt;greeting&gt;
                &lt;line1&gt;Ordered for you by Andrew Mullen on 09/21/12.&lt;/line1&gt;
                &lt;line2&gt;Save 20% on Holiday Cards November 20 - 30 at Shutterfly
                &lt;/line2&gt;
            &lt;/greeting&gt;
            &lt;shipAddr&gt;
                &lt;name&gt;burkina faso&lt;/name&gt;
                &lt;address1&gt;1234 burkina road&lt;/address1&gt;
                &lt;address2&gt;&lt;/address2&gt;
                &lt;city&gt;yako&lt;/city&gt;
                &lt;region&gt;R21&lt;/region&gt;
                &lt;postCode&gt;&lt;/postCode&gt;
                &lt;countryCode&gt;BF&lt;/countryCode&gt;
                &lt;countryName&gt;Burkina Faso&lt;/countryName&gt;
            &lt;/shipAddr&gt;
            &lt;shipMethod&gt;INTLSTD&lt;/shipMethod&gt;
            &lt;additionalFulfillers&gt;false&lt;/additionalFulfillers&gt;
            &lt;items&gt;
                &lt;item&gt;
                    &lt;itemNo&gt;36&lt;/itemNo&gt;
                    &lt;sku&gt;6X8FLATCARD06&lt;/sku&gt;
                    &lt;description&gt;6x8 Stationery Card - Stacy Claire Boyd&lt;/description&gt;
                    &lt;quantity&gt;1&lt;/quantity&gt;
                    &lt;product&gt;
                        &lt;stationery&gt;
                            &lt;formFactor&gt;6x8&lt;/formFactor&gt;
                            &lt;paperFinish&gt;MATTE&lt;/paperFinish&gt;
                            &lt;orientation&gt;LANDSCAPE&lt;/orientation&gt;
                            &lt;image&gt;
                                &lt;location&gt;http://orderfulfillment.shutterfly.com/fulfillment-test/image/1200/000020513524-7001536_28935--164044--315625--canvas.jpg
                                &lt;/location&gt;
                            &lt;/image&gt;
                            &lt;boc&gt;
                                &lt;location&gt;http://orderfulfillment.shutterfly.com/fulfillment-test/image/1200/000020513524-7001536_28935--164044--315626--canvas.jpg
                                &lt;/location&gt;
                            &lt;/boc&gt;
                            &lt;copyright&gt;
                                &lt;text&gt;6X8FLATCARD06&lt;/text&gt;
                            &lt;/copyright&gt;
                        &lt;/stationery&gt;
                    &lt;/product&gt;
                    &lt;envelopes&gt;
                        &lt;envelope&gt;
                            &lt;toAddress&gt;
                                &lt;font&gt;
                                    &lt;fontName&gt;Arial&lt;/fontName&gt;
                                    &lt;fontSize&gt;12&lt;/fontSize&gt;
                                &lt;/font&gt;
                                &lt;name&gt;FPO Tester&lt;/name&gt;
                                &lt;companyTitle&gt;&lt;/companyTitle&gt;
                                &lt;address1&gt;PSC 812 Box 2640&lt;/address1&gt;
                                &lt;address2&gt;&lt;/address2&gt;
                                &lt;city&gt;FPO&lt;/city&gt;
                                &lt;region&gt;AE&lt;/region&gt;
                                &lt;postCode&gt;09627&lt;/postCode&gt;
                                &lt;countryCode&gt;USA&lt;/countryCode&gt;
                                &lt;countryName&gt;United States of America&lt;/countryName&gt;
                            &lt;/toAddress&gt;
                            &lt;fromAddress&gt;
                                &lt;font&gt;
                                    &lt;fontName&gt;Arial&lt;/fontName&gt;
                                    &lt;fontSize&gt;12&lt;/fontSize&gt;
                                &lt;/font&gt;
                                &lt;name&gt;Andrew Mullen&lt;/name&gt;
                                &lt;companyTitle&gt;&lt;/companyTitle&gt;
                                &lt;address1&gt;2333 W. El Moro Circle&lt;/address1&gt;
                                &lt;address2&gt;&lt;/address2&gt;
                                &lt;city&gt;Mesa&lt;/city&gt;
                                &lt;region&gt;AZ&lt;/region&gt;
                                &lt;postCode&gt;85202&lt;/postCode&gt;
                                &lt;countryCode&gt;USA&lt;/countryCode&gt;
                                &lt;countryName&gt;United States of America&lt;/countryName&gt;
                            &lt;/fromAddress&gt;
                        &lt;/envelope&gt;
                    &lt;/envelopes&gt;
                &lt;/item&gt;
            &lt;/items&gt;
        &lt;/suborder&gt;
    &lt;/suborders&gt;
&lt;/order&gt;
</code></pre>

<p>Here is the XMLToArray() that I picked up from PHP.net:</p>

<pre><code>function XMLToArray($xml)
{
  if ($xml instanceof SimpleXMLElement) {
    $children = $xml-&gt;children();
    $return = null;
  }

  foreach ($children as $element =&gt; $value) {
    if ($value instanceof SimpleXMLElement) {
      $values = (array)$value-&gt;children();

      if (count($values) &gt; 0) {
        $return[$element] = XMLToArray($value);
      } else {
        if (!isset($return[$element])) {
          $return[$element] = (string)$value;
        } else {
          if (!is_array($return[$element])) {
            $return[$element] = array($return[$element], (string)$value);
          } else {
            $return[$element][] = (string)$value;
          }
        }
      }
    }
  }

  if (is_array($return)) {
    return $return;
  } else {
    return $false;
  }
} 
</code></pre>

<p>Thanks in advance.  Regards.</p>
