Reputation: 41
I am getting array/object by calling an api
If room types are more I am getting array like this
[HotelRoomResponse] => Array
(
[0] => stdClass Object
(
[rateCode] => 203735593
[rateDescription] => Mango Standard
[RoomType] => stdClass Object
(
[@roomTypeId] => 766936
[@roomCode] => 200163941
[description] => Mango Standard
[descriptionLong] => <strong><ul><li>One Twin Bed</li></ul></strong>This city view room measures 247 square feet (23 square meters). Complimentary wireless Internet access keeps you connected, and the 26-inch flat-screen TV offers cable channels. A coffee/tea maker is provided. The private bathroom has a shower with a rainfall showerhead, as well as complimentary toiletries. Climate control, air conditioning, and a ceiling fan are among the conveniences offered. <p></p>
)
)
[1] => stdClass Object
(
[rateCode] => 200928482
[rateDescription] => Mango Standard
[RoomType] => stdClass Object
(
[@roomTypeId] => 766936
[@roomCode] => 200163941
[description] => Mango Standard
[descriptionLong] => <strong><ul><li>One Twin Bed</li></ul></strong>This city view room measures 247 square feet (23 square meters). Complimentary wireless Internet access keeps you connected, and the 26-inch flat-screen TV offers cable channels. A coffee/tea maker is provided. The private bathroom has a shower with a rainfall showerhead, as well as complimentary toiletries. Climate control, air conditioning, and a ceiling fan are among the conveniences offered. <p></p>
)
)
)
If room type is only one I am getting following object
[HotelRoomResponse] => stdClass Object
(
[rateCode] => 1273814
[rateDescription] => Deluxe Double Room
[RoomType] => stdClass Object
(
[@roomTypeId] => 488629
[@roomCode] => 379721
[description] => Deluxe Double Room
[descriptionLong] => <strong><ul><li>2 beds</li></ul></strong>
)
)
I want to serailize the second object to first object i.e if we get more room types
How can I make above object to like this
[HotelRoomResponse] => Array
(
[0] =>stdClass Object
(
[rateCode] => 1273814
[rateDescription] => Deluxe Double Room
[RoomType] => stdClass Object
(
[@roomTypeId] => 488629
[@roomCode] => 379721
[description] => Deluxe Double Room
[descriptionLong] => <strong><ul><li>2 beds</li></ul></strong>
)
)
)
Also check the issue here http://developer.ean.com/docs/error-handling/special-cases/axis-net-json-issues/
I didn't have any solution for PHP.
Can any one help me.
Upvotes: 1
Views: 134
Reputation: 41
Here is my optimized solution
if(is_object($HotelRoomResponse)) {
$NewHotelRoomResponse[0] = $HotelRoomResponse;
$HotelRoomResponse = $NewHotelRoomResponse;
}
Upvotes: 1