1

My array ($response_array) is like this :

Array
(
    [Auth] => Array
        (
            [UserID] => test
            [UserIP] => 123
            [XmlVersion] => Testing Version
        )

    [SearchAvailRequest] => Array
        (
            [CountryCd] => ID
            [CityCd] => JOG
            [CheckIn] => 2016-01-08
            [CheckOut] => 2016-01-09
        )

    [SearchAvailResponse] => Array
        (
            [Hotel] => Array
                (
                    [0] => Array
                        (
                            [HotelNo] => 1
                            [HotelCode] => 321
                            [HotelName] => Test 1 Hotel
                            [RmGrade] => Deluxe
                            [RmGradeCode] => DLX
                        )

                    [1] => Array
                        (
                            [HotelNo] => 2
                            [HotelCode] => 212
                            [HotelName] => Test 2 & 1 Hotel
                            [RmGrade] => Deluxe
                            [RmGradeCode] => DLX
                        )

                )

        )

)

I want to send the hotel data to view

So the view display data like this :

Hotel Name
Room Type

I try like this :

Controller :

...
return view('frontend.hotel.main_list_hotel',[
                                'hotel' => $response_array
            ]);
...

View :

@foreach($hotel as $key=>$value)
{{ $key }}
{{ $value }}                     
@endforeach

But, there exist error like this :

htmlentities() expects parameter 1 to be string, array given (View: C:\xampp\htdocs...

Any suggestions on how I can solve this problem?

Thank you very much

2 Answers 2

1

If you want to iterate through hotels you need to iterate through $response_array['SearchAvailResponse']['Hotel'], not just $response_array.

Try passing hotel parameter as the following:

return view('frontend.hotel.main_list_hotel',[
  'hotel' => $response_array['SearchAvailResponse']['Hotel']
]);

And then in your view:

@foreach($hotel as $key=>$value)
{{ $key }}
{{ $value['HotelNo'] }}                     
@endforeach
Sign up to request clarification or add additional context in comments.

5 Comments

In localhost there is not an error. But there was an error in server. The error is like this : Undefined index: SearchAvailResponse
It only means there is no SearchAvailResponse in your response_array. Make sure response_array contains the value or check if the key exists before returning it to the view.
This seems to happen because the public ip on the server has not been registered to access the url api
I want to display the check in, check out, city and country in view. How to display it all in view? I am confused. Thank you
I need you help. Look here : stackoverflow.com/questions/36121287/…
0

You should try this . Here $value is also array

@foreach($hotel as $key=>$value)
{{ $key }}
{{ $value['HotelNo'] }}                     
@endforeach

1 Comment

There exist error. The error is like this : Use of undefined constant HotelNo - assumed 'HotelNo' (View: C:...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.