我试图传递多维数组来查看。但是当我尝试打印它会给我错误。以下是代码和错误。
控制器文件:
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
由于
答案 0 :(得分:3)
刀片模板代码{{ }}
已替换为echo()
。你不能回应数组。您需要从要显示的数组中获取字符串,例如:
@foreach($userArr as $users)
<h2>{{ $users['name'] }}</h2>
@endforeach