#1 jake
本文介绍多位数组如何在smarty中显示。
在控制器中:
$this->myarr = array(输出一下看看内容:
array(
array(
'name' => 'apple',
'count' => '1000',
),
array(
'name' => 'banana',
'count' => '2000'
),
),
array(
array(
'name' => 'cat',
'count' => '5000',
),
array(
'name' => 'dog',
'count' => '100'
),
),
);
dump($this->myarr);在模板中显示多维数组:
Array
(
[0] => Array
(
[0] => Array
(
[name] => apple
[count] => 1000
)
[1] => Array
(
[name] => banana
[count] => 2000
)
)
[1] => Array
(
[0] => Array
(
[name] => cat
[count] => 5000
)
[1] => Array
(
[name] => dog
[count] => 100
)
)
)
<{foreach from=$myarr item=arr1 name=thearr1}>
这里是第<{$smarty.foreach.thearr1.index}>列
<{foreach from=$arr1 item=arr2}>
<{foreach from=$arr2 item=single key=key}>
<{$key}>:<{$single}>
<{/foreach}>
<{/foreach}>
<{/foreach}>
最终结果:
这里是第0列
name:apple
count:1000
name:banana
count:2000
这里是第1列
name:cat
count:5000
name:dog
count:100
2012-08-04 15:00:21