我对Smarty和循环等有点新。我有这些数据通过,但需要在子数组之前得到初始ID,例如[114],[115]并且不确定如何。有什么想法吗?
我这样输出:
<pre>{$item2.$childs|print_r}</pre>
我需要从我使用的打印中获取数组Key,因为它是我需要获取的ID:
<ul class="ty-menu__submenu-list cm-responsive-menu-submenu">
{if $item2.$childs}
{hook name="blocks:topmenu_dropdown_3levels_col_elements"}
{foreach from=$item2.$childs key="i" item="item3" name="item3"}
{assign var="item3_url" value=$item3|fn_form_dropdown_object_link:$block.type}
{assign var="item3_id" value=$item3[id]|fn_check_is_active_menu_item:$block.type}
<pre>{$item2.$childs|print_r}</pre>
<li class="ty-menu__submenu-item{if $item3.active || $item3|fn_check_is_active_menu_item:$block.type} ty-menu__submenu-item-active{/if}{if $item3.class} {$item3.class}{/if}" data-mm-id="{$item3_id}">
<a{if $item3_url} href="{$item3_url}"{/if}
class="ty-menu__submenu-link">{$item3.$name}</a>
</li>
{/foreach}
{if $item2.show_more && $item2_url}
<li class="ty-menu__submenu-item ty-menu__submenu-alt-link">
<a href="{$item2_url}"
class="ty-menu__submenu-link">{__("text_topmenu_view_more")}</a>
</li>
{/if}
{/hook}
{/if}
</ul>
打印数组
Array
(
[114] => Array
(
[new_window] => 0
[item] => Butterfly Sofa Bean Bags
[href] => categories.view?category_id=114
[level] => 2
)
[123] => Array
(
[new_window] => 0
[item] => Avatar Lounger Bean Bags
[href] => categories.view?category_id=123
[level] => 2
)
[115] => Array
(
[new_window] => 0
[item] => Twin Couch Bean Bags
[href] => categories.view?category_id=115
[level] => 2
)
[116] => Array
(
[new_window] => 0
[item] => Versa Table Bean Bags
[href] => categories.view?category_id=116
[level] => 2
)
[113] => Array
(
[new_window] => 0
[item] => Acoustic Sofa Bean Bags
[href] => categories.view?category_id=113
[level] => 2
)
[164] => Array
(
[new_window] => 0
[item] => Twin Ottoman
[href] => categories.view?category_id=164
[level] => 2
)
[136] => Array
(
[new_window] => 0
[item] => Wing Ottoman Bean Bags
[href] => categories.view?category_id=136
[level] => 2
)
[112] => Array
(
[new_window] => 0
[item] => Fiorenze Bean Bags
[href] => categories.view?category_id=112
[level] => 2
)
)
答案 0 :(得分:0)
你可以像这样获得数组
$array = array(
'9' => array('4','6','8'),
'1' => '2',
'2' => '0',
'3' => '3',
'4' => '1');
foreach($array as $key => $value)
{
echo $mykey = $key;
}
答案 1 :(得分:0)
解决方案是设置密钥并输出如此
{foreach from=$item2.$childs key=item3_id item="item3" name="item3"}
{assign var="item3_url" value=$item3|fn_form_dropdown_object_link:$block.type}
<li class="ty-menu__submenu-item{if $item3.active || $item3|fn_check_is_active_menu_item:$block.type} ty-menu__submenu-item-active{/if}{if $item3.class} {$item3.class}{/if}" data-mm-id="{$item3_id}">
<a{if $item3_url} href="{$item3_url}"{/if}class="ty-menu__submenu-link">{$item3.$name}</a>
</li>
{/foreach}
输出
{$item3_id}