title: Convert multidimensional array into XML
body: <p><strong>Please read the bolded line below before you comment that this may be a duplicate. This has nothing to do with SimpleXML.</strong></p>
  
  <p>Let me start off by showing how the XML should be laid out. Please ignore the namespaces:</p>
  
  <pre><code> &lt;hot:SearchHotels&gt;
       &lt;hot:request&gt;
          &lt;hot1:Destination&gt;?&lt;/hot1:Destination&gt;
          &lt;hot1:HotelCityName&gt;?&lt;/hot1:HotelCityName&gt;
          &lt;hot1:HotelLocationName&gt;?&lt;/hot1:HotelLocationName&gt;
          &lt;hot1:HotelName&gt;?&lt;/hot1:HotelName&gt;
          &lt;hot1:CheckIn&gt;?&lt;/hot1:CheckIn&gt;
          &lt;hot1:CheckOut&gt;?&lt;/hot1:CheckOut&gt;
          &lt;hot1:RoomsInformation&gt;
             &lt;!--Zero or more repetitions:--&gt;
             &lt;hot1:RoomInfo&gt;
                &lt;hot1:AdultNum&gt;?&lt;/hot1:AdultNum&gt;
                &lt;hot1:ChildNum&gt;?&lt;/hot1:ChildNum&gt;
                &lt;!--Optional:--&gt;
                &lt;hot1:ChildAges&gt;
                   &lt;!--Zero or more repetitions:--&gt;
                   &lt;hot1:ChildAge age="?"/&gt;
                &lt;/hot1:ChildAges&gt;
             &lt;/hot1:RoomInfo&gt;
          &lt;/hot1:RoomsInformation&gt;
          &lt;hot1:MaxPrice&gt;?&lt;/hot1:MaxPrice&gt;
          &lt;hot1:StarLevel&gt;?&lt;/hot1:StarLevel&gt;
          &lt;hot1:AvailableOnly&gt;?&lt;/hot1:AvailableOnly&gt;
          &lt;hot1:PropertyType&gt;?&lt;/hot1:PropertyType&gt;
          &lt;hot1:ExactDestination&gt;?&lt;/hot1:ExactDestination&gt;
       &lt;/hot:request&gt;
    &lt;/hot:SearchHotels&gt;
  </code></pre>
  
  <p>Notice under hot1:RoomsInformation there is RoomInfo. I'm supposed to be able to send multiple RoomInfo nodes. <strong>But I'm using a PHP class to convert an array to this object to be submitted via SOAP.</strong></p>
  
  <p>Here's my array before it gets converted to an object:</p>
  
  <pre><code>$param = array(
              "Destination" =&gt; $destcode,
              "HotelCityName" =&gt; $city,
              "HotelLocationName" =&gt; "",
              "HotelName" =&gt; "",
              "CheckIn" =&gt; date("Y-m-d", strtotime($checkin)),
              "CheckOut" =&gt; date("Y-m-d", strtotime($checkout)),
              "RoomsInformation" =&gt; array (
                  "RoomInfo" =&gt; array(
                          "AdultNum" =&gt; 2,
                          "ChildNum" =&gt; 1,
                          "ChildAges" =&gt; array(
                              "ChildAge" =&gt; array(
                                  "age"=&gt;11
                              )
                          )
                      ),
                  "RoomInfo" =&gt; array(
                          "AdultNum" =&gt; 1,
                          "ChildNum" =&gt; 0,
                          "ChildAges" =&gt; array(
                              "ChildAge" =&gt; array(
                                  "age"=&gt;0
                              )
                          )
                      )
              ),
              "MaxPrice" =&gt; 0,
              "StarLevel" =&gt; 0,
              "AvailableOnly" =&gt; "false",
              "PropertyType" =&gt; "NotSet",
              "ExactDestination" =&gt; "false"
          );
  
  $param = arrayToObject($param) ;
  $obj = new stdClass(); 
  $obj-&gt;request=$param;
  $result = $test-&gt;SearchHotels($obj) ;
  </code></pre>
  
  <p>The problem is that after converting to an Object, there is only 1 RoomInfo and its the last one. My thought is because the RoomsInformation array has 2 identical KEY names. So how can I make this work?</p>
  
  <p>For your information, here is the SOAP class I use and the arrayToObject function:</p>
  
  <p><a href="http://pastebin.com/SBUN0FAF" rel="noreferrer">http://pastebin.com/SBUN0FAF</a></p>