在以下场景中,如何智能地以表格格式显示数组数据


How to display the array data in tabular format in smarty in following scenario?

我有一个名为$preview_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] => 
)

现在我必须以表格格式打印上述数据。我应该如何做到这一点。我想要以下表格格式的数据(即表格标题如下):

包装数量体积单位数量

数据应该显示为来自具有相同索引的所有相应数组的数据应该显示在一行中。下一行的下一个索引数据等等。那么如何在foreach构造的帮助下智能地实现这一点呢?提前谢谢。

{foreach from=$preview_data.pack key='index' item='value'}
<tr>
   <td>{$value}</td>
   <td>{$preview_data.quantity[$index]}</td>
   <td>{$preview_data.volume[$index]}</td>
   <td>{$preview_data.units[$index]}</td>
   <td>{$preview_data.amount[$index]}</td>
</tr>
{/foreach}