smarty详解foreach使用

smarty详解foreach使用

讲如何使用smarty foreach使用 如:{foreach from=$myArray item=foo}

{$foo}{/foreach}循环$myArray数组,打印值{$foo}出来

 

Attribute Name属性名称Type类型Required必要Default默认值Description描述
fromarray数组Yes必要n/a The array you are looping through
循环访问的数组
 
itemstring字符串Yes必要n/a The name of the variable that is the current element
当前元素的变量名
 
keystring字符串No可选n/a The name of the variable that is the current key
当前键名的变量名
 
namestring字符No可选n/a The name of the foreach loop for accessing foreach properties
用于访问foreach属性的foreach循环的名称
 

例 7-5. item属性

 

  1. 
      
          
    
    
    
  2. $arr
     = 
    array
    (
    "http://www.phpzy.com""www.phpzy.com""绿色php资源"
    );  
  3. $smarty
    ->assign(
    'myArray'$arr
    );  
  4. ?>  

 

Template to output $myArray in an un-ordered list

 

用模板以无序列表输出$myArray

 

 

  1. 
      
          
     
  2. {
    foreach
     from=
    $myArray
     item=foo}   
  3. {
$foo }  
{/
foreach
}  
 

 

The above example will output:

 

上例将输出:

阅读全文>>

转载于:https://my.oschina.net/lgc/blog/5299

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值