所以,我想在HTML表格中打印以下三维数组。
array ( 'BTC_YACC' => array ( 0 => array ( 'orderNumber' => '3585379', 'type' => 'sell', 'rate' => '0.0001', 'amount' => '128', 'total' => '0.0128', 'date' => '2014-05-18 08:54:37', ), ), )
这就是我提出的:( OrderNumber = OrderID)。
$tableopenorders = "<table><th>OrderID</th><th>Type</th><th>Rate</th><th>Amount</th><th>Total in BTC</th><th>Date placed</th><tr>";
for($element = 0; $element < count($decodedopenorders); $element++) {
$tableopenorders .= "<tr>";
for($row = 0; $row < 1; $row++) {
for ($col = 0; $col < 6; $col++) {
$tableopenorders .= "<td>".$decodedopenorders[$element][$row][$col]."</td>";
}
}
$tableopenorders .= "</tr>";
}
$tableopenorders .= "</table>";
最多有&#34; count($ decodingopenorders)&#34; $ elements,max。 $ decodingopenorders数组中有1行$ 6行和6行。迭代器开始为0,所以我使用了&lt;。
为什么这不起作用?
答案 0 :(得分:0)
当您遍历阵列时,您已将密钥更改为典型的0,1,2,3之外的其他内容。当您更改密钥时,$ decodingopenorders [0]不再有效,而是您必须调用$ decodedopenorders [ 'BTC_YACC'];所以这是我开始工作的代码:
$decodedopenorders = array (
'BTC_YACC' => array (
0 => array (
'orderNumber' => '3585379',
'type' => 'sell',
'rate' => '0.0001',
'amount' => '128',
'total' => '0.0128',
'date' => '2014-05-18 08:54:37')
)
);
$tableopenorders = "<table><th>OrderID</th><th>Type</th><th>Rate</th><th>Amount</th><th>Total in BTC</th><th>Date placed</th><tr>";
foreach ($decodedopenorders as $element => $value) {
$tableopenorders .= "<tr>";
foreach ($decodedopenorders[$element] as $row => $value){
foreach ($decodedopenorders[$element][$row] as $order) {
$tableopenorders .= "<td>". $order ."</td>";
}
}
$tableopenorders .= "</tr>";
}
$tableopenorders .= "</table>";
echo $tableopenorders;