【发布时间】:2021-05-06 02:54:31
【问题描述】:
我从 json 文件中获得的数组数据存在一些问题,但我想问题可能在于我使用 json decode 和 file_get_contents 在数组中转换的 json 结构。
基本上这是数组结构:
#items: array:4 [▼
"Monday, 1 de Fev de 2021" => array:5 [▼
"PM" => array:7 [▼
1 => "1140-10"
2 => "8498-25"
3 => "7076-19"
4 => "3380-20"
5 => "8194-24"
6 => "8288-22"
7 => "687-22"
]
"PT" => array:7 [▼
1 => "6406-2"
2 => "2976-19"
3 => "6029-8"
4 => "8130-8"
5 => "7530-8"
6 => "1071-18"
7 => "064-16"
]
"PTV" => array:7 [▶]
"PTN" => array:7 [▶]
]
"Sat, 31 de Jan de 2021" => array:2 [▼
"PTM" => array:7 [▶]
"PT" => array:7 [▶]
]
基本上日期是表格标题,带有字母的索引例如:“PTV”,“PM”,“PT”...”,是标题。
例如在“PM”里面有一些结果:
1 => "1140-10"
2 => "8498-25"
3 => "7076-19"
4 => "3380-20"
5 => "8194-24"
6 => "8288-22"
7 => "687-22"
其中索引(1,2,3..)为奖品,每个索引后的值为结果。
我需要将我的表格构建成上面这张图片
这是我的代码:
@if(sizeof($results) > 0)
@foreach($results as $date => $result)
<div class="col-xl-12">
<table class="table">
<caption>
{{ $date }}
</caption>
<thead>
<tr>
<th id="hoje" class="tabla-header"></th>
@foreach($result as $banca => $re)
<th id="{{ $banca }}" class="tabla-header">{{ $banca }}</th>
@endforeach
</tr>
</thead>
<tbody>
{{ sizeof($result) }}
@for ($i = 0; $i < 7; $i++)
<tr>
<td>1</td>
@for ($n = 0; $n < sizeof($result); $n++)
<td>{{ $result[] }}/td>
@endfor
</tr>
@endfor
</tbody>
</table>
</div>
@endforeach
@endif
【问题讨论】:
-
@for ($n = 0; $n < sizeof($result); $n++)如果您将此循环更改为 foreach,您可以通过<td>{{ $result[$key][$i] }}</td>访问这些值,我相信它会起作用吗? -
不是真的,我遇到的问题是每个索引 (PTM) 都有数据填充在每个索引中,我需要调用 PTM 的第一个位置,而不是其他位置,结构不是以我想要的方式构建表格非常简单。
-
好吧,我相信我做到了。