smarty詳解foreach使用php
講如何使用smarty foreach使用 如:{foreach from=$myArray item=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
$arr = array ( "http://www.phpzy.com" , "www.phpzy.com" , "綠色php資源" );
$smarty ->assign( 'myArray' , $arr );
?>
Template to output $myArray in an un-ordered listpost
用模板以無序列表輸出$myArray ui
{ foreach from= $myArray item=foo}
- {
$foo }
{/ foreach }
The above example will output:spa
上例將輸出: code
閱讀全文>>ip