一 代码
index.php
<?php include_once("../config.php"); //调用Smarty类库文件 $arr = array('computerbook','name' => 'PHP从入门道具精通','unit_price' => array('price' => '¥65.00','unit' => '本')); $smarty->assign('title','使用Smarty读取数组'); $smarty->assign('arr',$arr); $smarty->display('2/index.tpl'); ?>
index.tpl
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>{ $title }</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <link rel="stylesheet" href="../css/style.css" /> </head> <body> 购书信息:<br> 图书类别:{ $arr[0] }<br /> 图书名称:{ $arr.name }<br /> 图书单价:{ $arr.unit_price.price }/{ $arr.unit_price.unit } </body> </html>
二 运行结果
购书信息:
图书类别:computerbook
图书名称:PHP从入门道具精通
图书单价:¥65.00/本
图书类别:computerbook
图书名称:PHP从入门道具精通
图书单价:¥65.00/本