foreach can be used equal to for
解决方案 »
- 【求教】请问,有没有可能在LAMP环境下使得没有.php后缀名的文件成为可执行的脚本
- PHP模拟POST的方法
- 两个二维数组合并
- 哪位大哥 帮小弟 诠释下~
- 急急,各位大侠帮下忙~~小弟刚弄php遇到点问题
- 初学php,在安装phpMyAdmin的时候遇到问题
- 淘宝api的R2级别字段,如何不让他显示*号
- mysql 转义函数谁给小弟一个
- 为什么session会一直保留纪录的信息?不是关掉浏览器,就没有了吗?
- 我做了一个简单的意见信箱,收到的信却是乱码,请问如何解决?
- 求一个简单的URL参数加密解密的代码
- 转:权限设计 有用质数组成权限集合的,有用2的n次幂组成权限值集合的,我都是用直接将用户和权限代码(自定义格式)存储的,判断时,wh
查找函数: function _compile_tag($template_tag)
往下拉,找到这个函数里的第一个switch,添加for和/for。如下。
switch ($tag_command) {
case 'for':
$this->_push_tag('for');
return $this->_compile_for_start($tag_args);
case '/for':
$this->_pop_tag('for');
return "<?php endfor; ?>";
case 'include':
return $this->_compile_include_tag($tag_args);最后再添加for的处理函数,将以下函数加到class smarty里:
function _compile_for_start($tag_args)
{
$attrs = $this->_parse_attrs($tag_args);
$arg_list = array(); if (empty($attrs['name'])) {
return $this->_syntax_error("for: missing 'name' attribute", E_USER_ERROR, __FILE__, __LINE__);
}
if (!isset($attrs['from'])) {
return $this->_syntax_error("for: missing 'from' attribute", E_USER_ERROR, __FILE__, __LINE__);
}
if (!isset($attrs['to'])) {
return $this->_syntax_error("for: missing 'to' attribute", E_USER_ERROR, __FILE__, __LINE__);
}
return "<?php for(\$this->_tpl_vars[{$attrs['name']}]={$attrs['from']};\$this->_tpl_vars[{$attrs['name']}]<={$attrs['to']};\$this->_tpl_vars[{$attrs['name']}]++): ?>";
}
-------------------------------
大功告成。试一试
{for name=i from=1 to=8}
<td> 第{$i}行 *** </td>
{/for}
for还是有一定的要求的。我估计后几个版本smarty还是会把它加上。
以此为例
{for name=i from=1 to=1000}
{$i}
{/for}在我现在用的2.6.10版里。如果不指定一个长度为1000的数组做为loop的话,以下语句是什么也不会输出的!我就得多建一个无用的长度为1000的数组。
{section name=i start=1 max=1000 loop=$nothing}
{%i.index%}
{/section}