smarty循环数组显示下拉菜单

test.tpl
<select name=”slevel” id=”slevel”>
<{foreach item=t from=$typename key=key}>
<option value=”<{$key}>”><{$t}></option>
<{/foreach}>
</select>

test.php

//定义分类数组
$typename = array(‘1’=>’脑袋,’2’=>’cdbrain’,’3’=>’webphper’,’4’=>’naodai’,);
$smarty->assign(“typename”,$typename);

注意:smarty 里 foreach $key是数组下标,$t是数组内容

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.