由于工作环境受限,我需要将此数组的一半放入一个表格行,另一半放入另一个 .
这是数组(已经按我需要的顺序排序):
Array
(
[product] => KFE-1221
[description] => Classic Blue
[current_stock] => 630
[purchase_order] =>
[total_sales] => 0
[avail_to_sell] => 630
[size_run1] => 15
[size_run2] => 62
[size_run3] => 122
[size_run4] => 113
[size_run5] => 102
[size_run6] => 92
[size_run7] => 63
[size_run8] => 61
[size_run9] => 0
[size_run10] => 0
)
我需要将“size_run1”-“size_run10”处的数组拆分为单独的表行。
以前,当我不需要 size_run 时,我可以将数组显示到表中(标准 foreach)。由于要求,我将其添加。(是的,我正在使用已弃用的 php)
<?php
while($data = mssql_fetch_assoc($result_ats)) {
if ($data['avail_to_sell'] <= 0){
echo '<tr class="error">';
}
else {
echo '<tr>';
}
foreach($data as $k => $v){
echo '<td>'.$v.'</td>';
echo '</tr>';
}
}
?>
我想将它保留为一个数组的原因是因为我使用一个查询来获取所有信息,并且使用我正在使用的庞大数据库,我将其拆分在模板端而不是拥有更有意义分离数组并添加一个将产品匹配到 size_run 的过程。
在不将数组拆分为不同数组的情况下执行此操作的最佳方法是什么?
我想要的输出,即将数组'$v'分成两个单独的表,如下所示:
<tr>
<th>product</th>
<th>description</th>
<th>current_stock</th>
<th>purchase_order</th>
<th>total_sales</th>
<th>avail_to_sell</th>
</tr>
<tr>
<th>size_run1</th>
<th>size_run2</th>
<th>size_run3</th>
<th>size_run4</th>
<th>size_run5</th>
<th>size_run6</th>
<th>size_run7</th>
<th>size_run8</th>
<th>size_run9</th>
<th>size_run10</th>
</tr>