Php 在以下场景中,如何在smarty中以表格格式显示阵列数据?
我有一个名为Php 在以下场景中,如何在smarty中以表格格式显示阵列数据?,php,arrays,foreach,smarty,Php,Arrays,Foreach,Smarty,我有一个名为$preview\u data的数组,如下所示: Array ( [op] => preview [id] => [form_submitted] => yes [company_id] => [product_id] => [pack] => Array ( [0] => 10 [1] => 20
$preview\u data
的数组,如下所示:
Array
(
[op] => preview
[id] =>
[form_submitted] => yes
[company_id] =>
[product_id] =>
[pack] => Array
(
[0] => 10
[1] => 20
[2] => 30
[3] => 40
)
[quantity] => Array
(
[0] => 2
[1] => 4
[2] => 6
[3] => 8
)
[volume] => Array
(
[0] => 100
[1] => 200
[2] => 300
[3] => 400
)
[units] => Array
(
[0] => 5
[1] => 7
[2] => 9
[3] => 10
)
[amount] => Array
(
[0] => 3.00
[1] => 6.00
[2] => 9.00
[3] => 12.00
)
[date] =>
[applicable_states] =>
[rebate_total_cnt] =>
)
现在我必须以表格格式打印上述数据。我应该如何做到这一点。我希望数据的表格格式如下(即表格标题如下所示):
包装数量体积单位数量
数据应显示为来自具有相同索引的所有相应阵列的数据,并应显示在一行中。下一行上的下一个索引数据,依此类推。那么,如何在smarty中借助foreach构造实现这一点呢?提前感谢。{foreach from=$preview\u data.pack key='index'item='value'}
{$value}
{$preview_data.quantity[$index]}
{$preview_data.volume[$index]}
{$preview_data.units[$index]}
{$preview_data.amount[$index]}
{/foreach}
您知道如何用PHP实现您的要求吗?因为你可以很容易地把它翻译成Smarty。@WesleyMurch:我是Smarty的一个新手,所以我现在不能这么做。如果你能发布一个以上代码的答案,这将对我非常有帮助。
pack quantity volume units amount