
smarty里面的section 怎样遍历关联的多维数组
1个回答
展开全部
1 $arr
= array(
2
array('id'=>1,'title'=>'title1'),
3
array('id'=>2,'title'=>'title2'),
4
array('id'=>3,'title'=>'title3')
5 );
6
7
$smarty->assign('news',$arr);
1 {section name=sn loop=$news}
2 {if $smarty.section.sn.first}
3
<table>
4
<th>id</th>
5
<th>title</th>
6 {/if}
7
<tr>
8
<td>{$news[sn].id}</td>
9
<td>{$news[sn].title}</td>
10
</tr>
11 {if $smarty.section.sn.last}
12
</table>
13 {/if}
14 {sectionelse}
15 there is no news.
16 {/section}
显示结果如下(是一个表格的样子,以下显示的没有加样式):
1 id title
2 1 title1
3 2 title2
4 3 title3
= array(
2
array('id'=>1,'title'=>'title1'),
3
array('id'=>2,'title'=>'title2'),
4
array('id'=>3,'title'=>'title3')
5 );
6
7
$smarty->assign('news',$arr);
1 {section name=sn loop=$news}
2 {if $smarty.section.sn.first}
3
<table>
4
<th>id</th>
5
<th>title</th>
6 {/if}
7
<tr>
8
<td>{$news[sn].id}</td>
9
<td>{$news[sn].title}</td>
10
</tr>
11 {if $smarty.section.sn.last}
12
</table>
13 {/if}
14 {sectionelse}
15 there is no news.
16 {/section}
显示结果如下(是一个表格的样子,以下显示的没有加样式):
1 id title
2 1 title1
3 2 title2
4 3 title3
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询