Php 在两列表格上显示关联数组中的项目

Php 在两列表格上显示关联数组中的项目,php,html,arrays,html-table,associative,Php,Html,Arrays,Html Table,Associative,我正在尝试使用此关联数组将项目从关联数组显示到一个两列表中 foreach($ID=>$Info)的库存(/code>) 但我得到的却是: ------------------------------------------------------------------ |Name: shoes | Name: shoes |Description: nike | Description: nike ----------

我正在尝试使用此关联数组将项目从关联数组显示到一个两列表中
foreach($ID=>$Info)的库存(/code>)

但我得到的却是:

------------------------------------------------------------------
|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  

我在这把小提琴中为这个伪表创建了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>');
echo(“”);
foreach($this->inventory as$ID=>$Info){
回声(“”);
回音('Name:'.$Info['Name'].

Description:'.$Info['Description'..

); 回声(“”); } 回声(“”);
它说您正在尝试,但不是说您遇到了什么问题。假设数据键匹配并且$this->inventory返回一个array@charlietfl我对这个问题进行了改进,尽可能多地包含细节。谢谢这很简单…你复制了输出代码…以前从未注意到这一部分…我们真的不知道预期结果是什么,所以需要一个计数器来检查
%2
,所以你只需在循环的每一次循环中关闭
,然后删除你现在的
TD
输出行中的一行
$this->inventory
以$ID为索引的数组,还是以
$ID
为键的对象?如果索引…可以使用
表示
,并按2递增,这是一个很好的示例,说明为什么不应将表格用于非表格格式data@Qiqa:如果你喜欢这个答案并且它解决了你的问题,就接受这个答案。
------------------------------------------------------------------
|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  
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>');