【发布时间】:2017-06-18 11:49:11
【问题描述】:
我正在使用 Laravel 5.2 并使用以下方法将数组结果集返回到我的视图中
return view('home')->with('devices', $devices)
我尝试在刀片中使用以下内容循环遍历我的数组数据
@foreach($devices as $device)
{{ $device[name] }} has
{{ $device[views] }}
@endforeach
使用$device[name] 抛出Use of undefined constant name - assumed 'name'
我也试过像这样循环遍历结果
@foreach($devices as $device)
{{ $device->name }} has
{{ $device->views }}
@endforeach
【问题讨论】:
-
数组键应该被引用。也有例外,但这不是其中之一。
-
@AlexeyMezenin 在那个例子中我们都使用了这个词吗?虽然标记不同....
标签: php arrays laravel laravel-5