foreach,foreachelse函數(shù)
foreach,foreachelse函數(shù)
#使用方法:
foreach 用於處理簡(jiǎn)單陣列(數(shù)組中的元素的類型一致),它的格式比section 簡(jiǎn)單許多,缺點(diǎn)是只能處理簡(jiǎn)單數(shù)組.
foreach 必須和/foreach 成對(duì)使用,並且必須指定
from 和 item 屬性.
name
屬性可以任意指定(字母、數(shù)字和下劃線的組合).
foreach 可以嵌套,但必須保證嵌套中的foreach 名稱唯一.
from 屬性(通常是數(shù)組)決定循環(huán)的次數(shù).
foreachelse 語句在from
變數(shù)沒有值的時(shí)候被執(zhí)行.
test.php:
$smarty->assign('custid', array(1000 ,1001,1002));
test.html:
{foreach from=$custid item=curr_id}
id: {$curr_id}<br>
{/foreach}
#輸出: