smarty详解foreach使用

smarty详解foreach使用php

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

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

     

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

    例 7-5. item属性
    oop

     

     
    
    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 listpost

     

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

     

     

     
    
    1.  
           
         
    2. {
      foreach
       from=
      $myArray
       item=foo}   
    3. {
    4. $foo }
    5.  
    6. {/
      foreach
      }  
    7.  

     

    The above example will output:spa

     

    上例将输出: code

    阅读全文>>ip

    相关文章
    相关标签/搜索