如何在视图中解决未定义的索引?

时间:2016-01-21 04:21:15

标签: php laravel laravel-5

我的数组($ response_array)是这样的:

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
                        )

                )

        )

)

我想发送酒店数据以查看

所以视图显示数据如下:

Hotel Name
Room Type

我试着这样:

控制器:

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

查看:

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

但是,存在这样的错误:

ErrorException in TestController.php line 181: Undefined index: SearchAvailResponse

在localhost中没有错误。但是服务器出现了错误

有关如何解决此问题的任何建议?

非常感谢

0 个答案:

没有答案