Php smarty v3在foreach中显示嵌套数组元素

Php smarty v3在foreach中显示嵌套数组元素,php,multidimensional-array,foreach,smarty,smarty3,Php,Multidimensional Array,Foreach,Smarty,Smarty3,我已经找过了,但似乎找不到解决我问题的有效方法 我试图从一个数组中仅提取2个元素: $menu.contents.text和$menu.contents.url 如果您还没有猜到的话,arrays变量就是菜单。当我运行代码时 这是我目前使用的代码: <form name='jump'> <select name='menu' onChange='location=document.jump.menu.options[document.jump.menu.selectedInde

我已经找过了,但似乎找不到解决我问题的有效方法

我试图从一个数组中仅提取2个元素:
$menu.contents.text
$menu.contents.url

如果您还没有猜到的话,arrays变量就是菜单。当我运行代码时

这是我目前使用的代码:

<form name='jump'>
<select name='menu' onChange='location=document.jump.menu.options[document.jump.menu.selectedIndex].value;' size='1' value='GO'>
{foreach from=$menu item=result}
    {if $result.contents}
        {foreach from=$result.contents item=mc}
            <option value="{$mc.url}">{$mc.text}</option>
        {/foreach}
    {/if}
{/foreach}
</select>
</form>

有人知道我做错了什么吗?

我认为第一个foreach不在正确的位置。试试这个:

{if !empty($menu.contents)}
  {foreach from=$menu.contents item=contentsItem} {* Loop through the contents array *}
    {foreach from=$contentsItem item=mc}
      <option value="{$mc.url}">{$mc.text}</option>
    {/foreach}
  {/foreach}
{/if}
{if!empty($menu.contents)}
{foreach from=$menu.contents item=contentsItem}{*循环内容数组*}
{foreach from=$contentsItem item=mc}
{$mc.text}
{/foreach}
{/foreach}
{/if}

非常感谢您,我一直对smarty的foreach感到困惑。
{if !empty($menu.contents)}
  {foreach from=$menu.contents item=contentsItem} {* Loop through the contents array *}
    {foreach from=$contentsItem item=mc}
      <option value="{$mc.url}">{$mc.text}</option>
    {/foreach}
  {/foreach}
{/if}