开发者

Smarty, get values from array, using loop to step between keys

开发者 https://www.devze.com 2023-03-18 20:19 出处:网络
In my last thread开发者_Python百科 i did not explain myself correctly... i use Smarty v2.5 I need to get values for array $myArray[0] which are under var1, var2, var3... keys

In my last thread开发者_Python百科 i did not explain myself correctly... i use Smarty v2.5 I need to get values for array $myArray[0] which are under var1, var2, var3... keys

{section name="myLoop" start=1 loop=100}

   $myArray[0].var{$smarty.section.myLoop.index}

{/section}

i need to make result string actually get array value like if i use

{$myArray[0].var1}
{$myArray[0].var2}
{$myArray[0].var3}
etc.


From the smarty docs:

{$foo.$bar}   <-- display variable key value of an array, similar to PHP $foo[$bar]

Haven't tested, but I would do:

{section name="myLoop" start=1 loop=100}
    {assign var="key" value="var".$smarty.section.myLoop.index}
    {$myArray[0].$key}
{/section}


I think {for} works, but {$foo.$bar} is for v3 and does not work on v2.5

0

精彩评论

暂无评论...
验证码 换一张
取 消