【发布时间】:2019-08-01 08:40:03
【问题描述】:
我试图在表格上显示每组数组(第一维)。每次页面加载都会创建很多数组和表,这就是我想到使用 foreach 的原因。返回的数组来自控制器。
我返回的数组如下所示:
数组:$appreq
Array
(
[0] => Array
(
[0] => Array
(
[Name] => Lot Survey Plans and Specifications
[Document] => -
[Id] => 10
[Is_Received] => 0
[Is_Personal_Submission] => 1
)
[1] => Array
(
[Name] => Others (Specify)
[Document] => -
[Id] => 11
[Is_Received] => 0
[Is_Personal_Submission] => 1
)
)
[1] => Array
(
[0] => Array
(
[Name] => Fire Protection Plan (if applicable)
[Document] =>
[Id] => 12
[Is_Received] => 0
[Is_Personal_Submission] => 1
)
)
[2] => Array
(
[0] => Array
(
[Name] => Vicinity Map or Location Plan within a Two(2) Kilometer Radius
[Document] => -
[Id] => 13
[Is_Received] => 0
[Is_Personal_Submission] => 1
)
[1] => Array
(
[Name] => Site Development Plan
[Document] => assets/uploads/ca060d9b-93d2-4fcd-8a8b-113bfac8dbbf/Architectural Permit/Site Development Plan...hollow-knight.jpg
[Id] => 14
[Is_Received] => 0
[Is_Personal_Submission] => 1
)
[2] => Array
(
[Name] => Perspective
[Document] => -
[Id] => 15
[Is_Received] => 0
[Is_Personal_Submission] => 1
)
数组:$ancillarypermit
该表应该显示在第一个 D 数组中划分的数据,然后行是数组的下一个维度,我的 td 应该包含:Name 和 Is_Received 值。请不要介意表格标题(本地间隙等),它是另一个 foreach 循环的一部分,我只是在 tbody 上遇到了问题。
来自数组:$appreq
第一维:[0] => 数组是局部间隙表
2 => 数组是消防安全表
3 => 数组是建筑许可表
预期表:
我如何使用我的 foreach 变量,以及我如何调用数组以显示在 .我真的希望有人能帮助我解决这个问题,在此先感谢
更新 --------------
我尝试按照建议执行以下操作:
<?php foreach($ancillarypermit as $row => $data) :
foreach($appreq as $row => $value) : ?>
<table style="text-align: left; width: 50%">
<thead>
<tr>
<th scope="col">#</th>
<th width='10' style="text-align:center;">Received</th>
<th scope="col">Requirement</th>
</tr>
</thead>
<tbody>
<h5><strong><?= $data->permit->Name ?></strong></h5>
<?php
foreach ($value as $key => $values) :
?>
<tr>
<th scope="row">1</th>
<td width='150' style='text-align: center; vertical-align: middle; padding: 3px'>
<?php
echo CheckboxX::widget([
'name'=>'s_1',
'value'=>$values['Is_Received'],
// 'readonly'=>true,
'pluginOptions'=>['threeState'=>false]
]);
?>
</td>
<td> <?= $values['Name'] ?> </td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endforeach;
endforeach;?>
【问题讨论】:
-
能否请您添加要显示的预期 html 表格。
-
@InsaneSkull 嗨,我更新了我的问题并添加了一张图片,谢谢