<?php include './Vendor/Smarty.class.php'; $smart=new Smarty(); define("CC","中国制造"); $arr=array( "0" => array( "id" =>"001", "name" => "小伟", ), "1" =>array( "id" => "002", "name" =>"小王" ) ); //把数组$arr 传递给 rs(HTML中) $smart->assign('rs',$arr); $smart->display('my.html');
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <!-- 循环输出 --> {foreach $rs as $values} {$values['id']} {/foreach} <!--循环结束--> </body> </html>
也可以这么写
{foreach from=$rs item-'values'}
{$values['id']}
{/foreach}