smarty的foreach能否遍历oop对象呢?该如何处理

WBOY
Release: 2016-06-13 10:00:07
Original
903 people have browsed it

smarty的foreach能否遍历oop对象呢?
我知道{section}可以遍历oop对象,但是不懂的foreach是否也可以呢?

------解决方案--------------------
foreach 是除 section 之外处理循环的另一种方案(根据不同需要选择不同的方案).
foreach 用于处理简单数组(数组中的元素的类型一致),它的格式比 section 简单许多,缺点是只能处理简单数组.
foreach 必须和 /foreach 成对使用,且必须指定 from 和 item 属性.
name 属性可以任意指定(字母、数字和下划线的组合).
foreach 可以嵌套,但必须保证嵌套中的 foreach 名称唯一.
from 属性(通常是数组)决定循环的次数.
foreachelse 语句在 from 变量没有值的时候被执行.


------解决方案--------------------
当然是可以的
例如
{foreach from=$arrMembersList item=objMemberInfo}
{$objMemberInfo->iBookId}:{$objMemberInfo->strMembersName}
{/foreach}
------解决方案--------------------
foreach from=$array item=tt
$array[tt].

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!