smarty的foreach能否遍曆oop對象呢?該如何處理

來源:互聯網
上載者:User
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].
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.