在Smarty中显示多维数组

时间:2015-03-03 10:25:17

标签: php arrays multidimensional-array smarty

这是我的阵列。

Array
(
[0] => Array
    (
        [crop_id] => 34
        [group_id] => asd
        [crop_name] => dfg
        [varieties] => Array
            (
                [0] => Array
                    (
                        [crop_variety_id] => 43
                        [variety_name] => hjk
                        [stages] => Array
                            (
                                [0] => Array
                                    (
                                        [crop_id] => 34
                                        [stage_id] => 76
                                        [stage_name] => First Inspection
                                        [area] =>     --   
                                    )

                                [1] => Array
                                    (
                                        [crop_id] => 34
                                        [stage_id] => 77
                                        [stage_name] => Vegetative Inspection
                                        [area] =>     --   
                                    )

我需要在此数组中显示 stage_name 。我正在使用smarty的{section}循环。

我在$masterData

中有我的数据数组
{section name=i loop=$masterData}               
  {section name=j loop=$masterData[i].varieties}
    {section name=k loop=$masterData[j].stages}
        <th>{$masterData[i].varieties[j].stages[k].stage_name}</th>
    {/section}     
  {/section}
{/section}

这让我空虚。如何从此多维数组中显示stage_name

1 个答案:

答案 0 :(得分:2)

您错过了loop=$masterData[i].varieties[j].stages而不是loop=$masterData[j].stages 试试:

{section name=i loop=$masterData}               
    {section name=j loop=$masterData[i].varieties}
        {section name=k loop=$masterData[i].varieties[j].stages}
            <th>{$masterData[i].varieties[j].stages[k].stage_name}</th>
        {/section}     
    {/section}
{/section}