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