Smarty成員方法:append()

2018-10-20 11:18 更新

Name

append() — 把值追加到數(shù)組。

說明

void append(mixed var);
void append(string varname,
            mixed var,
            bool merge);

在追加的時候,字符串將轉(zhuǎn)換成數(shù)組的值。你可以顯式傳遞鍵值對,或是聯(lián)合數(shù)組。如果設(shè)置第三個參數(shù)為true時,該值將合并到原有數(shù)組上而并非追加。

Technical Note

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()

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號