如何在laravel刀片中传递多维数组?

时间:2017-05-15 19:37:57

标签: php laravel multidimensional-array

我试图传递多维数组来查看。但是当我尝试打印它会给我错误。以下是代码和错误。

控制器文件:

foreach($countrygroup as $val){
        //$userArr[] = $val->userid;
        $users =  DB::table('timelines')->where('id', '=', $val->userid)->first();
        $userArr[$val->userid]['name'] = $users->name;//$users->name;
        $userArr[$val->userid]['avatar'] = $users->avatar_id;
        //$userArr[$val->userid]['image']=$users->image;            
    }
    //echo '<pre>'; print_r($userArr); die();
      return $theme->scope('groups/country', compact('userArr','trending_tags','countrygroupnamee'))
      ->render();

刀片文件代码:

@foreach($userArr as $users)
    <h2>{{ $users}}</h2>                                                                
 @endforeach

enter image description here

由于

1 个答案:

答案 0 :(得分:3)

刀片模板代码{{ }}已替换为echo()。你不能回应数组。您需要从要显示的数组中获取字符串,例如:

@foreach($userArr as $users)
    <h2>{{ $users['name'] }}</h2>                                                                
@endforeach