Laravel:未定义的偏移量:3?

时间:2017-03-06 10:01:01

标签: laravel laravel-5 laravel-5.2

我收到错误

  

未定义的偏移:3

我想要的是编辑,如果$ view_360和$ iframe_title为空,找到iframe并删除它。任何建议我怎么能这样做?

for ($i=0; $i <= count($view_360); $i++) {

      if(!empty($view_360[$i])){
        if($request->view360_id[$i] == "undefined"){
          $view_360_iframe = new View360();
        }
        else {
         $view_360_iframe = View360::findOrFail($request->view360_id[$i]);
        }
        $view_360_iframe->property_id = $property->id;
        $view_360_iframe->title = $iframe_title[$i];
        $view_360_iframe->iframe = $view_360[$i];
        $view_360_iframe->save();

      }
      if(empty($view_360[$i]) && empty($iframe_title[$i])){
          $view_360_iframe = View360::findOrFail($request->view360_id[$i]);
          $view_360_iframe->delete();
      }
    }

1 个答案:

答案 0 :(得分:3)

看起来您需要$i < count($view_360)而不是$i <= count($view_360)。所以你有$ view_360 [0],$ view_360 [1]和$ view_360 [2],但你没有$ view_360 [3]。