Smarty成員方法:appendByRef()

2018-10-20 11:19 更新

Name

appendByRef() — 引用追加

說明

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

和 append() 一樣,把值追加到數(shù)組,但以引用的方式來傳遞值。

技術(shù)說明

在PHP5中,appendByRef()在大部分時候都是沒有必要的。只當你希望在模板中可以修改某個PHP數(shù)組的值,才有可能會使用到appendByRef(),當然更好的方法是通過傳遞對象、改變對象的成員變量來達到目的。

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.5. appendByRef()

<?php
// 追加鍵值對
$smarty->appendByRef('Name', $myname);
$smarty->appendByRef('Address', $address);
?>

參見 append()assign() 和 getTemplateVars().

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

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號