I have an array
array('foo_1' => 1, 'bar_1' =>1, 'foo_2' => 2, 'bar_2' => 2, ... )
for($i = 1; $i<=12; $i++){
echo $month['foo_'.$i];
}
And I don’t understand how can I access the values from it using Smarty.
{counter start=0 skip=1 assign="i"}
{section name = month start = 0 loop = 12 step = 1}
{if isset($arr.foo_.$i)}
{$arr.bar_$i}
{/if}
{counter}
{/section}
But it doesn’t work. The main issue is – How I can access array[‘foo_1’] in smarty ? Can you please help?
You must build the key before accessing it in the array. Use assign to build the complete name.
Your attempt
{$arr.foo_.$i}means accessing the subkey$iin the array under$arr.foo_.