2017-05-15 57 views
0

我嘗試通過多維數組來查看。但是,當我嘗試打印它會給我錯誤。以下是代碼和錯誤。如何通過laravel blade中的多維數組?

控制器的文件:

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

感謝

+0

在foreach循環中查詢數據庫? Ouch ... – Eric

回答

1

刀片模板標籤{{ }}被替換爲echo()。你不能回顯數組。您需要從要顯示的數組中取出字符串,例如:

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

謝謝@jeremy哈里斯 –