一 代码
index.php
<?php include("../config.php"); $obj = array( array("id" => 1, "bigclass" => "计算机图书","smallclass" => array(array("s_id" => 1, "s_type" => "PHP"))), array("id" => 2, "bigclass" => "历史传记","smallclass" => array(array("s_id" => 2, "s_type" => "中国历史"), array("s_id" => 3, "s_type" => "世界历史"))), array("id" => 3, "bigclass" => "畅销小说","smallclass" => array(array("s_id" => 4, "s_type" => "网络小说"),array("s_id" => 5, "s_type" => "科幻小说")))); $smarty->assign('title','section循环控制'); $smarty->assign("obj", $obj); $smarty->display("8/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> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>{$title}</title> <link rel="stylesheet" href="../css/style.css" /> </head> <body> <table width="100" border="0" align="left" cellpadding="0" cellspacing="0"> {section name=sec1 loop=$obj} <tr> <td colspan="2">{$obj[sec1].bigclass}</td> </tr> {section name=sec2 loop=$obj[sec1].smallclass} <tr> <td width="25"> </td> <td width="75">{$obj[sec1].smallclass[sec2].s_type}</td> </tr> {/section} {/section} </table> </body> </html>
二 运行结果
相关推荐
计算机前端-核心编程. Smarty11section遍历枚举数组.avi
smarty中section的使用 smarty section php
主要介绍了smarty的section嵌套循环用法,结合简单实例形式分析了Smarty使用section进行嵌套循环操作的实现技巧,需要的朋友可以参考下
本篇文章是对Smarty中如何获取数组的长度以及smarty调用php函数的方法进行了详细的分析介绍,需要的朋友参考下
计算机前端-核心编程. Smarty08foreach循环数组.avi
主要介绍了smarty模板引擎使用内建函数foreach循环取出所有数组值的方法,实例分析了foreach循环遍历数组的几种常用技巧,需要的朋友可以参考下
计算机前端-核心编程. Smarty12section控制步长、起始点、循环次数.avi
1、Smarty介绍及应用的优缺点 Smarty是一个使用...2、Smarty的配置3、Smarty的应用:变量,循环…数组是最常用的方式,可以帮助我们循环列表,和快速访问打理数据,如果要循环数组我们可以使用Smarty内置的方法section
在实际操作中与section 功能一样,但foreach在Smarty一般用来处理一维数组。2、include 多功能使用3、IF条件语句的使用4、literal strip 文本的处理技巧 literal 数据将被当作文本处理,此时模板将忽略其内部的所有...
Smarty模板中的for循环,新建plugins文件,简化代码!
软件介绍 1、Smarty介绍及应用的优缺点 Smarty是一个使用PHP写出来的PHP模板引擎,目的是要...数组是最常用的方式,可以帮助我们循环列表,和快速访问打理数据,如果要循环数组我们可以使用Smarty内置的方法section
使用foreach语句循环输出数组。 {% foreach key=key item=item from=$infobook %} {% $key %} => {% $item %} {% /foreach %} include {% include file='08/table.tpl' name='编程词典网' value='htt://...
计算机前端-核心编程. Smarty10section语法格式.avi
section 功能一样,但foreach在Smarty一般用来处理一维数组。 2、include 多功能使用 3、IF条件语句的使用 4、literal strip 文本的处理技巧 literal 数据将被当作文本处理,此时模板将忽略其内部的所有字符...
在smarty中数组是经常会用到的,循环遍历数组用 section 或者 foreach ,如何得到数组长度或者判断一个数组个数呢
主要介绍了smarty模板判断数组为空的方法,实例分析了两种smarty判断数组为空的方法,非常简单实用,需要的朋友可以参考下
有了它,肯定会为您学习smarty带来很大的帮助。
php+smarty输出资讯列表,生成html静态