简体   繁体   中英

Foreach loop using smarty

I need some hint regarding php syntax using smarty version 2.6.29..

The code looks like..

[-php-] 
// $array is assigned from another .php file
foreach($array as $arr){
    echo $arr;  
}
[-/php-]

Any help would be really helpful...

Try this...

{foreach from=$array item=arr}
    <li>{$arr}</li>
{/foreach}

Source: http://www.smarty.net/docsv2/en/language.function.foreach.tpl

Try this (with your syntax [-php-]):

[-php-]foreach from=$array item=arr[-/php-]
    [-php-]print_r($arr)[-/php-] // some code
[-php-]/foreach[-/php-]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM