How to pass an array into a PHP SoapClient call How to pass an array into a PHP SoapClient call php php

How to pass an array into a PHP SoapClient call


'stay' has to be defined just once. This should be the right answer:

$xml = array('reservation' => array('stays' => array(    'stay' => array(                    array(                          'start_date' => '2011-01-01',                          'end_date'   => 2011-01-15                    ),                    array(                          'start_date' => '2011-01-01',                          'end_date'   => 2011-01-15                    )              )      )));


Assuming that when you instantiated $soapClient, you did so in WSDL mode, the following should work:

$stay1 = new stdClass();$stay1->start_date = "2011-01-01";$stay1->end_date = "2011-01-15";$stay2 = new stdClass();$stay2->start_date = "2011-01-01";$stay2->end_date = "2011-01-15";$stays = array();$stays[0] = $stay1;$stays[1] = $stay2;$soapClient->saveReservation(    array("reservation" => array("stays" => $stays)));


I also had this problem and found the solution. Stays needs to be an array with ascending keys starting with 0.

$client = new SoapClient('http://myservice.com?wsdl');$stays[] = array('startDate'=>'01-01-2013', 'endDate'=>'02-02-2013');$stays[] = array('startDate'=>'02-02-2013', 'endDate'=>'03-03-2013');$params = array(  'reservation' => array('stays'=>$stays));$client->saveReservation($params);

I found my answer on this page: https://bugs.php.net/bug.php?id=45284