请先阅读下面的粗体行,然后再评论这可能是重复的。这与SimpleXML无关。将多维数组转换为XML
让我首先展示如何布置XML。请忽略名称空间:
<hot:SearchHotels>
<hot:request>
<hot1:Destination>?</hot1:Destination>
<hot1:HotelCityName>?</hot1:HotelCityName>
<hot1:HotelLocationName>?</hot1:HotelLocationName>
<hot1:HotelName>?</hot1:HotelName>
<hot1:CheckIn>?</hot1:CheckIn>
<hot1:CheckOut>?</hot1:CheckOut>
<hot1:RoomsInformation>
<!--Zero or more repetitions:-->
<hot1:RoomInfo>
<hot1:AdultNum>?</hot1:AdultNum>
<hot1:ChildNum>?</hot1:ChildNum>
<!--Optional:-->
<hot1:ChildAges>
<!--Zero or more repetitions:-->
<hot1:ChildAge age="?"/>
</hot1:ChildAges>
</hot1:RoomInfo>
</hot1:RoomsInformation>
<hot1:MaxPrice>?</hot1:MaxPrice>
<hot1:StarLevel>?</hot1:StarLevel>
<hot1:AvailableOnly>?</hot1:AvailableOnly>
<hot1:PropertyType>?</hot1:PropertyType>
<hot1:ExactDestination>?</hot1:ExactDestination>
</hot:request>
</hot:SearchHotels>
在hot1下的通知:RoomsInformation里面有RoomInfo。我应该能够发送多个RoomInfo节点。 但我正在使用PHP类将数组转换为通过SOAP提交的此对象。
这里是我的阵列之前,它被转换为对象:
$param = array(
"Destination" => $destcode,
"HotelCityName" => $city,
"HotelLocationName" => "",
"HotelName" => "",
"CheckIn" => date("Y-m-d", strtotime($checkin)),
"CheckOut" => date("Y-m-d", strtotime($checkout)),
"RoomsInformation" => array (
"RoomInfo" => array(
"AdultNum" => 2,
"ChildNum" => 1,
"ChildAges" => array(
"ChildAge" => array(
"age"=>11
)
)
),
"RoomInfo" => array(
"AdultNum" => 1,
"ChildNum" => 0,
"ChildAges" => array(
"ChildAge" => array(
"age"=>0
)
)
)
),
"MaxPrice" => 0,
"StarLevel" => 0,
"AvailableOnly" => "false",
"PropertyType" => "NotSet",
"ExactDestination" => "false"
);
$param = arrayToObject($param) ;
$obj = new stdClass();
$obj->request=$param;
$result = $test->SearchHotels($obj) ;
的问题是转换为对象之后,只有1 RoomInfo和最后一个。我的想法是因为RoomsInformation数组有2个相同的KEY名称。那我该如何做这项工作?
为了您的信息,这里是SOAP I类使用和arrayToObject功能:
[如何将数组转换为SimpleXML](http://stackoverflow.com/q/1397036/1503018) – sectus
如果使用SOAP,那么php内置的SoapClient可以处理数组 – Fracsi
您可以'吨,而不是该阵列。不管你有多少个'RoomsInformation'条目,如果他们有相同的密钥,他们确实只有一个。 –