在我的视图中,我的表行跨度是动态的:
<tr>
<?php $no = 1;
foreach($idn as $ia){?>
<td width="17" align="center" >E</td>
<td width="134" align="left" colspan="2" >Indikator Kinerja Jabatan </td>
<td colspan="4" align="left" bordercolor="#FFFFFF" > <p>
<?php echo $no++ ?>.
<?php echo $ia->indikator_kompetensi; ?><br/>
</p></td>
答案 0 :(得分:0)
在放入foreach
以显示为html之前进行分组
<?php
$yourArr = [
["id"=>1,"name"=>"name1","desc"=>"description1"],
["id"=>1,"name"=>"name1","desc"=>"description2"],
["id"=>2,"name"=>"name2","desc"=>"description3"],
["id"=>2,"name"=>"name2","desc"=>"description4"],
];
print_r($yourArr);
$neededArr = array();
foreach($yourArr as $k=>$v){
$neededArr[$v['id']]["name"] = $v["name"];
$neededArr[$v['id']]["child"][] = ["desc"=>$v["desc"]];
}
print_r($neededArr);
?>
程序输出:
name1 description1
description2
-----------------------------------
name2 description3
description4
-----------------------------------
答案 1 :(得分:0)
此外,您还可以在for-each之外以及最后一个for-each中使用所有内容来显示数据。
<tr>
<?php $no = 1;
<td width="17" align="center" >E</td>
<td width="134" align="left">Indikator Kinerja Jabatan </td>
<td align="left" bordercolor="#FFFFFF" ><p>
foreach($idn as $ia){?>
echo $no . $ia->indikator_kompetensi . '<br/>';
$no++;
}
?>
</p></td>
<tr>
答案 2 :(得分:0)
这是我的问题的答案
<tr>
<td width="17" align="center" >E</td>
<td width="134" align="left" colspan="2" >Indikator Kinerja Jabatan </td>
<td colspan="4" align="left" bordercolor="#FFFFFF" > <p>
<?php $no = 1;
foreach($idn as $ia){?>
<?php echo $no++ ?>.
<?php echo $ia->indikator_kompetensi; ?><br/>
<?php } ?> </p></td>
</tr>
谢谢大家对我的帮助