简体   繁体   English

Smarty concat / foreach分配

[英]Smarty concat/foreach assignment

I have a main array: 我有一个主数组:

$occupations = ['hs','uni','parent'];

and other multiple array of type 和其他多个数组类型

$columns_hs;$columns_uni;

etc. I want to foreach through the "$occupations" array and then foreach through the other arrays but cant seem to get the right syntax. 等等。我想遍历“ $ occupations”数组,然后遍历其他数组,但似乎无法获得正确的语法。 Here is my code: 这是我的代码:

{foreach from=$occupations item=ov key=ok}
    {foreach from=$columns_`$ov`}
        do something
    {/foreach}
{/foreach}

I am using smarty 2. 我正在使用smarty 2。

您可以尝试创建自己的varible与分配

Declare one array colums 声明一个数组列

$colums = array(
 'hs' => [1,2,3,4],
 'uni' => [5,6,7,8]
);

and your code in foreach is 你在foreach中的代码是

{foreach from=$occupations item=ov key=ok}
    {foreach from=$columns[$ov]}
        do something
    {/foreach}
{/foreach}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM