如何在单值返回时将Object数组转换为数组,
这里是我得到的o / p当我只得到一家酒店时,我怎么能以一种方式将其转换为代码中显示的0th [0]值。我在o / p获得单一酒店时遇到问题。 print_r($result); via foreach()
stdClass Object
(
[cityId] => 000000000020
[checkInDate] => 2013-12-20
[checkOutDate] => 2013-12-21
[customerId] =>
[customerAccountType] => SH01
[customerType] =>
[currency] => INR
[noOfRoomsRequested] => 1
[searchAvailabilityResult] => stdClass Object
(
[hotelId] => IXW1
[hotelName] => Ginger Jamshedpur
)
)
===what i want is ================================
stdClass Object
(
[cityId] => 000000000020
[checkInDate] => 2013-12-20
[checkOutDate] => 2013-12-21
[customerId] =>
[customerAccountType] => SH01
[customerType] =>
[currency] => INR
[noOfRoomsRequested] => 1
[searchAvailabilityResult] => Array
(
[0] => stdClass Object
(
[hotelId] => IXW1
[hotelName] => Ginger Jamshedpur
)
)
)
答案 0 :(得分:0)
单值
$result->searchAvailabilityResult = array($result->searchAvailabilityResult);
非常感谢#Maciej Sz
答案 1 :(得分:0)
$ result-> searchAvailabilityResult = get_object_vars($ result-> searchAvailabilityResult);