//foreach.php <?php require_once("smarty.inc"); $arrId = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0); $arrInfo = array('name' => 'andylin', 'id' => '1101', 'address' => "beijing"); $smarty->assign("arrId", $arrId); $smarty->assign("arrInfo", $arrInfo); $smarty->display("foreach.tpl"); ?> //foreach.tpl {* print simple array *} info of simple array: <br> <table border="1"> <br> <td>id</td> </br> {foreach from=$arrId item=nId} <tr> <td>{$nId}</td> </tr> {/foreach} </table> info of another array: <br> <table border="1"> <br> <td>id</td> <td>key</td> <td>value</td> <br> {foreach key=strKey item=strName from=$arrInfo} <tr> <td>{$nIndex++|default:0}</td> <td>{$strKey}</td> <td>{$strName}</td> </tr> {/foreach} </table>