如何在smarty中显示嵌套的foreach值

时间:2015-06-01 08:42:00

标签: php smarty

我需要在smarty中显示嵌套的for-each循环值。

I have the array like


Array ( 
     [err] => 0 
     [code] => 0 
     [msg] => Success 
     [retval] => Array ( 
         [0] => Array ( 
              [id] => 8 
              [thread_id] => 8 
              [body] => Hi test message 
              [priority] => 1 
              [sender_id] => 11 
              [cdate] => 2015-06-01 12:26:55 
              [status] => 1 
              [subject] => Hi 
              [user_name] => soniya kaliappan 
         ) 
     ) 
)

如何在smarty中获得retval ['body']值。请帮帮我。

1 个答案:

答案 0 :(得分:1)

只需在另一个foreach -

中运行foreach即可
{foreach from=$yourarray item=loopVal}
  {foreach from=$loopVal.retval key=retval item=retVal}
    {$retVal.body}
  {/foreach}
{/foreach}

或者retval内只有一个数组 -

{foreach from=$yourarray item=loopVal}
    {$loopVal.retVal.0.body}
{/foreach}