這是我想要在HTML table
中顯示的Array
。多維數組計算
$itemss =array(
array("name"=>"Blue Pen", "Description"=>"Atlas", "UnitPrice"=>13.50, " AvailableStock "=>200),
array("name"=>"80 P-Book", "Description"=>"Atlas", "UnitPrice"=>65," AvailableStock "=>100),
array("name"=>"A4 Paper 500", "Description"=>"Atlas", "UnitPrice"=>500," AvailableStock "=>20),
array("name"=>"Red Pen", "Description"=>"Atlas", "UnitPrice"=>13.50," AvailableStock "=>256),
array("name"=>"Back Pen", "Description"=>"Atlas", "UnitPrice"=>13.50," AvailableStock "=>156));
輸出結果應該像這樣在表中。
Item Name |Description|Unit Price|Available Stock|Stock Value
Blue Pen Atlas 13.50 200 xxxx
Total Stock Value |xxxxxx
這我做了什麼到現在:
<?php
$itemss =array(
array("name"=>"Blue Pen", "Description"=>"Atlas","UnitPrice"=>13.50,"AvailableStock"=>200),
array("name"=>"80 P-Book", "Description"=>"Atlas", "UnitPrice"=>65," AvailableStock"=>100),
array("name"=>"A4 Paper 500","Description"=>"Atlas","UnitPrice"=>500,"AvailableStock"=>20),
array("name"=>"Red Pen", "Description"=>"Atlas", "UnitPrice"=>13.50,"AvailableStock"=>256),
array("name"=>"Back Pen", "Description"=>"Atlas", "UnitPrice"=>13.50,"AvailableStock"=>156));
?>
<table border="1">
<tr>
<th>Item Name</th>
<th>Description</th>
<th>Unit Price</th>
<th>Available Stock</th>
<th>Stock Value</th>
</tr>
<?php
foreach($itemss as $Rockband)
{
echo '<tr>';
foreach(array_values($Rockband) as $key => $item)
{
echo "<td>$item</td>";
}
echo '</tr>';
}
?>
</table>
什麼問題? – billyonecan
數組中沒有'Stock Value',你的子數組只包含4個元素。 – jeroen
庫存值=單價*有庫存 – user3312802