Reputation: 557
how to assign associative array value to a variable say,
{* $a = array('key1'=>123) *}
{assign var="a.key2" value=234}
without pre-assigning in php script or using a {php} tag?
Upvotes: 2
Views: 4081
Reputation: 66
smarty code
{assign var="keys" value=','|explode:'key1,key2,key3'}
{assign var="values" value=','|explode:'value1,value2,value3'}
{assign var="a" value=$keys|@array_combine:$values}
{foreach from=$a item="value" key="key"}
{$key} | {$value}<br>
{/foreach}
and {$a.key2}
result
key1 | value1
key2 | value2
key3 | value3
and value2
Upvotes: 3