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语句,可以将一些相关的信息存放在一维数组中来设置值。