如何解决如何在laravel刀片中显示嵌套的数组数据?
如何访问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","5": {
"size_description": "X LARGE","4": {
"size_description": "LARGE","2": {
"size_description": "SMALL","on_hand": "0"
}
},"CHA": {
"3": {
"size_description": "MEDIUM","1": {
"size_description": "X SMALL","VINSA": {
"5": {
"size_description": "X LARGE","VINDE": {
"5": {
"size_description": "X LARGE","on_hand": "0"
}
}
}
}
我将此数组作为 items 传递到我的laravel刀片文件中,并访问相关数据。但是我很难访问 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 - ...........
解决方法
@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:
<?php
$uniqueSizes = [];
?>
@foreach ($item['color_size_grid'] as $color => $sizes)
@foreach ($sizes as $size)
@if (isset($uniqueSizes[$size['size_description']]))
@continue
@endif
{{ $size['size_description'] }}
{{ ($loop->last ? '' : ',') }}
<?php
$uniqueSizes[$size['size_description']] = true;
?>
@endforeach
@endforeach
</strong>
</td>
<td></td>
</tr>
<tr>
<td>
<strong>
Colors:
@foreach ($item['color_size_grid'] as $color => $sizes)
{{ $color }}:
@foreach ($sizes as $size)
{{ $size['size_description'] }}
{{ ($loop->last ? '' : ',') }}
@endforeach
@endforeach
</strong>
</td>
<td></td>
</tr>
</table>
</div>
</div>
@endforeach
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。