Question

I've an array titled $preview_data as follows:

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] => 
)

Now I've to print the above data in a table format. How should I achieve this. I want the data in table format as below(i.e. the headings of the table are as below):

pack   quantity    volume  units   amount

The data should be displayed as data from all the respective arrays with same index should be displaye in one line. The next index data on next line and so on. So how to achieve this in smarty with the help of foreach construct? Thanks in advance.

Was it helpful?

Solution

{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}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top