W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
append() — 把值追加到數(shù)組。
void append(mixed var);
void append(string varname,
mixed var,
bool merge);
在追加的時候,字符串將轉(zhuǎn)換成數(shù)組的值。你可以顯式傳遞鍵值對,或是聯(lián)合數(shù)組。如果設(shè)置第三個參數(shù)為true時,該值將合并到原有數(shù)組上而并非追加。
The merge
parameter respects array keys, so if you merge two numerically indexed arrays, they may overwrite each other or result in non-sequential keys. This is unlike the PHP array_merge()
function which wipes out numerical keys and renumbers them.
Example 14.4. append()
<?php // 直接使用和assign()差不多 $smarty->append('foo', 'Fred'); // 這里,foo已經(jīng)變成了模板中的一個數(shù)組。 $smarty->append('foo', 'Albert'); $array = array(1 => 'one', 2 => 'two'); $smarty->append('X', $array); $array2 = array(3 => 'three', 4 => 'four'); // 下面會增加第二個X數(shù)組的元素 $smarty->append('X', $array2); // 傳遞聯(lián)合數(shù)組 $smarty->append(array('city' => 'Lincoln', 'state' => 'Nebraska')); ?>
參見 appendByRef()
, assign()
和 getTemplateVars()
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: