我是PHP Blade / Laravel的新手,我正试图在HTML中显示一个变量内的数组。
所以我得到了一个名为{{ print_r($products) }}
的变量,首先我做了这个:
Array
(
[0] => Array
(
[title] => Belt
[image] => img/products/belt.jpg
[price] => 79.00
[specialPrice] =>
)
[1] => Array
(
[title] => Hat
[image] => img/products/hat.jpg
[price] => 89.00
[specialPrice] => 69.00
)
[2] => Array
(
[title] => Bag
[image] => img/products/bag.jpg
[price] => 99.00
[specialPrice] => 59.00
)
[3] => Array
(
[title] => Scarf
[image] => img/products/scarf.jpg
[price] => 119.00
[specialPrice] =>
)
)
1
这给了我:
@foreach($products as $key => $item)
<p>{{@item->title}}</p>
@endforeach
所以,我希望将此数组显示为HTML。我试过这个:
library(data.table) # not necessary unless you want the data in this format for other reasons
library(dplyr)
library(corrr)
但那没有用。我做错了什么?
答案 0 :(得分:0)
试试这个:
@foreach($products as $product)
<p>{{$product->title}}</p>
@endforeach
或者
@foreach($products as $product)
<p>{{$product[title]}}</p>
@endforeach