简体   繁体   中英

how to find a key of array in smarty

hii to all..i am new to smarty..and i didnt look depth in smarty..i had an array.how can i get a particular key value as a string in smarty..

thx in advance.

If you already have an existing array assigned via smarty, then you can access keys and values using the smarty foreach loop.

{foreach from=$array key="key" item="value"}
{$key} => {$value}
{/foreach}
$country=array('INDIA','United State');
$smarty->assign('country',$country);

Then you can use like
{$country[0]}
{$country[1]}


$country=array('IND'=>INDIA','US'=>'United State');
$smarty->assign('country',$country);

Then you can use Something Like This
{$country.IND}
{$country.US}
$myarray['mykey'] = 'myvalue';
$smarty->assign('myarray', $myarray);

The value is: <strong>{$myarray.mykey}</strong>

I'd say that you can find all this and more just looking at the documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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