1.在PHP程序中
//定義一維數組
$color = array("red","green","blue");
//定義二維數組
$student[] = array("name"=>"zhangsan","birthday"=>"2008-1-1");
$student[] = array("name"=>"lisi","birthday"=>"2008-1-2");
$student[] = array("name"=>"wangwu","birthday"=>"2008-1-3");
$student[] = array("name"=>"lilili","birthday"=>"2008-1-4");
//設置模板變量
$smarty->assign("color",$color);
$smarty->assign("student",$student);
2.在Smarty模板中.
下面是一維數組:
<font color="{$color[0]}">紅色</font><font color="{$color[1]}">綠色</font><font color="{$blue[0]}">藍色</font>
下面是二維數組:
{section name=list loop=$student}
{$student[list].name}
{sectionelse}
無內容
{/section}
3.爲了不在php程序中出現過多的$smarty->assign語句,能夠將一些相關的信息存放在一維數組中來設置值。