亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

smarty里面的section 怎樣遍歷關聯的多維數組?

smarty里面的section 怎樣遍歷關聯的多維數組?

GCT1015 2019-04-03 10:07:38
smarty里面的section 怎樣遍歷關聯的多維數組
查看完整描述

3 回答

?
largeQ

TA貢獻2039條經驗 獲得超8個贊

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



查看完整回答
反對 回復 2019-04-13
?
富國滬深

TA貢獻1790條經驗 獲得超9個贊

$smarty -> assign("newsreco",$newsreco);

"$newsreco"這里加上雙引號的話,值還沒有傳遞就直接被展開成Array了。

另外如果可以用foreach的時候,還是用foreach比較好,section的效率比foreach低很多,這不是一個喜歡與否的問題。

查看完整回答
反對 回復 2019-04-13
  • 3 回答
  • 0 關注
  • 877 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號