【发布时间】:2021-01-20 05:08:48
【问题描述】:
如何访问 laravel 刀片文件中的嵌套数组数据?
我的数组:
{
"id": 2271,
"amt_item": "PS839137",
"image_name": "PS839137.jpg",
"company": "01",
"division": "PAP",
"color_description": "VINTAGE SAGE",
"item_description": "SHT SLV CRISSCROSS TEE",
"season_code": "SP18",
"season_name": null,
"season_description": null,
"wholesale_price": ".00",
"retail_price": ".00",
"color_code": "VINSA",
"vendor_code": "DDJJG",
"vendor_desc": "JIANGYIN CITY JINGE GARMENT COMPANY",
"color_size_grid": {
"CORA": {
"1": {
"size_description": "X SMALL",
"on_hand": "0"
},
"3": {
"size_description": "MEDIUM",
"on_hand": "0"
},
"5": {
"size_description": "X LARGE",
"on_hand": "0"
},
"4": {
"size_description": "LARGE",
"on_hand": "0"
},
"2": {
"size_description": "SMALL",
"on_hand": "0"
}
},
"CHA": {
"3": {
"size_description": "MEDIUM",
"on_hand": "0"
},
"4": {
"size_description": "LARGE",
"on_hand": "0"
},
"1": {
"size_description": "X SMALL",
"on_hand": "0"
},
"5": {
"size_description": "X LARGE",
"on_hand": "0"
},
"2": {
"size_description": "SMALL",
"on_hand": "0"
}
},
"VINSA": {
"5": {
"size_description": "X LARGE",
"on_hand": "0"
},
"3": {
"size_description": "MEDIUM",
"on_hand": "0"
},
"4": {
"size_description": "LARGE",
"on_hand": "0"
},
"2": {
"size_description": "SMALL",
"on_hand": "0"
},
"1": {
"size_description": "X SMALL",
"on_hand": "0"
}
},
"VINDE": {
"5": {
"size_description": "X LARGE",
"on_hand": "0"
},
"4": {
"size_description": "LARGE",
"on_hand": "0"
},
"1": {
"size_description": "X SMALL",
"on_hand": "0"
},
"3": {
"size_description": "MEDIUM",
"on_hand": "0"
},
"2": {
"size_description": "SMALL",
"on_hand": "0"
}
}
}
}
我将此数组作为 items 传递给我的 laravel Blade 文件并访问相关数据。但是我很难访问 color_size_grid 数组中的数据。如何在 foreach 循环中打印所有 size_description?提前致谢。
在我的刀片文件中做了什么:
@foreach ($items as $item)
<div class="print-block" style="page-break-inside: avoid;">
<div class="print-block__img">
<img src="" alt="">
</div>
<div class="print-block__details">
<h3>{{$item['item_description']}}</h3>
<div class="code">{{$item['amt_item']}}</div>
<div class="price">
<strong>W:</strong> USD {{$item['wholesale_price']}} | <strong>R:</strong> USD {{$item['retail_price']}}
</div>
<table class="other-info">
<tr>
<td>
<strong>Sizes: </strong>
</td>
<td></td>
</tr>
<tr>
<td>
<strong>Colors: </strong>
</td>
<td></td>
</tr>
</table>
</div>
</div>
@endforeach
对于 Sizes,现在我想打印 color_size_grid 数组中的所有 size_descriptions。
每种颜色的可用尺寸如下:
Sizes:
CORA - X SMALL, MEDIUM, X LARGE, LARGE, SMALL
CHA - ...........
【问题讨论】:
标签: arrays laravel loops nested laravel-blade