section.php
<?php
require "smarty.inc.php";//加载模板引擎
$tpl->assign('title',"section循环");
$contact= array(
array('name'=> '孙某','fax'=> '1234', 'email' => 'luo@123','phone' => '123456'),
array('name'=> '随某','fax'=> '1234', 'email' => 'luo@123','phone' => '123456')
);
$tpl->assign('contact',$contact);
$tpl->display('section.tpl');
$output = $tpl->fetch("section.tpl");
//输出静态页面的路径
$PageName = "./section.html";
$fp = fopen($PageName,"w");
fwrite($fp,$output);
fclose($fp);
?>
section.tpl
<!DOCTYPE HTML>
<HTML lang="zh-CN">
<head>
<title>联系人信息表</title>
</head>
<body>
<table border ="1" width ="80%" align ="center">
<caption><h1>联系人列表</h1></caption>
<tr>
<th>姓名</th><th>传真</th><th>电子邮件</th><th>联系电话</th>
</tr>
<{section name=line loop=$contact}>
</tr>
<td><{$contact[line].name}></td>
<td><{$contact[line].fax}></td>
<td><{$contact[line].email}></td>
<td><{$contact[line].phone}></td>
</tr>
<{sectionelse}>
<p>数组$contact中没有任何值</p>
<{/section}>
</table>
</body>
</html>
有图有真相: