How to pass an array into a PHP SoapClient call

那年仲夏 提交于 2019-11-27 22:18:50

'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))
);

Try this:

$xml = array(
  'stays' => array(
    'stay' => array(
      array( /* start end */ ),
      array( /* start end */ ),
      array( /* start end */ )
    )
  )
);

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!