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

    相關文章
    相關標籤/搜索