foreach和section遍历数组

来源:互联网 发布:淘宝网购物女装夏装2015款 编辑:程序博客网 时间:2024/05/23 00:09
昨天由于教室装win8,没有及时写博客,呵呵...今天补上。

昨天主要学习了:

1.foreach遍历数组:

php文件:
<?php
$b = array('1','2','3'); 
include"libs/Smarty.class.php";
$smarty = new Smarty();
$smarty->reInitSmarty(); //加载Smarty模版的初始化类,把界定符改为<{和}>,模板目录改为一个地方。
$smarty->assign("bb",$b);  //传递索引数组变量
$smarty->display("abc.tpl");
?>
模版文件:
<html>
<head></head>
<body>
<{foreach from=$bb item=value}>
<{$value}>
<{/foreach}>
</body>
</html>

2.section遍历数组:

php文件:
<?php
$b = array('1','2','3'); 
include"libs/Smarty.class.php";
$smarty = new Smarty();
$smarty->reInitSmarty(); //加载Smarty模版的初始化类,把界定符改为<{和}>,模板目录改为一个地方。
$smarty->assign("bb",$b);  //传递索引数组变量
$smarty->display("abc.tpl");
?>
模版文件:
<html>
<head></head>
<body>
<{section name=b1 loop=$bb}>
<{$bb[b1]}>
<{/section}>
</body>

</html>

这部分掌握还稍有欠缺,还要继续努力。