Smarty, get values from array, using loop to step between 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
精彩评论