dongxianshuai8927 2017-05-15 19:37
浏览 66
已采纳

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

I have try to pass the multidimensional array to view. But when I try to print It will give me error. Below are the code and error.

Controller File:

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();

Blade File Code:

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

enter image description here

Thanks

  • 写回答

1条回答 默认 最新

  • douzhanlie9209 2017-05-15 19:39
    关注

    The blade template tags {{ }} are replaced with an echo(). You can't echo an array. You need to get the string out of the array that you want to display, for example:

    @foreach($userArr as $users)
        <h2>{{ $users['name'] }}</h2>                                                                
    @endforeach
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用