具有多维数组的Foreach-Laravel Blade模板 [英] Foreach with a multidimensional array - Laravel Blade templating

查看:164
本文介绍了具有多维数组的Foreach-Laravel Blade模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数组结果集,我试图遍历每个结果,然后将它们回显到页面上.我正在使用Laravel 5.2和刀片模板引擎

I have the following array result set, I'm trying to loop through each of the results and just echo them out onto the page. I'm using Laravel 5.2 and the blade templating engine

Collection {#240 ▼
  #items: array:3 [▼
    0 => array:2 [▼
      "name" => "desktop"
      "views" => "349"
    ]
    1 => array:2 [▼
      "name" => "mobile"
      "views" => "151"
    ]
    2 => array:2 [▼
      "name" => "tablet"
      "views" => "68"
    ]
  ]
}

这是我到目前为止所拥有的

This is what I have so far

@foreach($devices as $device)
    $key = 0; $key++; $key < 2;
    {{ $device[$key] }},
@endforeach

推荐答案

@foreach($devices as $device)
    {{ $device->name }}

    {{ $device->views}}
@endforeach

就足够了.

这篇关于具有多维数组的Foreach-Laravel Blade模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆