php - How to get array key by value from array in smarty template? -
how array key value array in smarty template?
from below can last inserted key need particular key value in smarty.
{$array|@array_keys|@array_pop}
assuming have following array:
$smarty->assign("array", [ '0' => 5, 'a' => 'abc', 'd' => 'xyz' ]);
you can use in smarty:
{assign var="key" value='xyz'|array_search:$array} {if $key !== false} key {$key} {/if}
to find key given value in array. of course work described array_search function
Comments
Post a Comment