我正在尝试使用此关联数组将关联数组中的项显示为两列表
foreach($this->inventory as $ID => $Info)
。
"<table width ='100%'>\n";
foreach($this->inventory as $ID => $Info) {
echo"<tr>";
echo"<td>".$Info['name'] <br>$Info['description']." </td>";
echo"<td>".$Info['name'] <br>$Info['description']."</td>";
echo"</tr>";
}
</table>
问题是每行显示两次项目。 我希望它显示如下:
------------------------------------------------------------------
|Name: shoes |Name: bag
|Description: nike |Description: swing bag
-----------------------------------------------------------------
|Name: socks |Name: ear phones
|Description: black and white |Description: beats
-----------------------------------------------------------------
|Name: earrings |Name: phone
|Description: diamond studs |Description: blackberry
但是我得到了这个:
------------------------------------------------------------------
|Name: shoes | Name: shoes
|Description: nike | Description: nike
-----------------------------------------------------------------
|Name: bag | Name: bag
|Description: swing bag |Description: swing bag
-----------------------------------------------------------------
|Name: ear phones |Name: ear phones
|Description: beats |Description: beats
答案 0 :(得分:1)
我在这个小提琴http://jsfiddle.net/hnek2/
中为这个伪表创建了CSS现在你可以使用这个PHP:
echo('<div class="tbl">');
foreach($this->inventory as $ID => $Info) {
echo('<div class="block">');
echo('<p>Name: ' . $Info['name'] . '</p><p>Description: ' . $Info['description'] . '</p>');
echo('</div>');
}
echo('</div>');