?
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
void append_by_ref
(string
varname, mixed var)
void append_by_ref
(string
varname, mixed var, boolean merge)
This is used to append values to the templates by reference. If you
append a variable by reference then change its value, the appended
value sees the change as well. For objects, append_by_ref() also avoids
an in-memory copy of the appended object. See the PHP manual on
variable referencing for an in-depth explanation. If you pass the
optional third parameter of true, the value will be merged with the
current array instead of appended.
本函數(shù)用于采用引用的方式把變量的值添加到原有值之后。如果采用引用的方式添加了一個(gè)變量,那么當(dāng)這個(gè)變量的值改變時(shí),被添加的值也隨之改變。對(duì)于
對(duì)象,append_by_ref()函數(shù)也能夠避免對(duì)于被添加對(duì)象的內(nèi)存拷貝。關(guān)于變量引用的進(jìn)一步解釋可以查看PHP手冊(cè)。如果第三個(gè)可選參數(shù)設(shè)置為
true,數(shù)值將會(huì)和現(xiàn)有數(shù)組合并,而不是添加在數(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 array_merge() function of PHP which wipes out numerical keys and renumbers them.
注意:使用第三個(gè)參數(shù)“merge”時(shí)要考慮到數(shù)組的索 引,所以,如果添加和被添加的數(shù)組都是以數(shù)字為索引,他們會(huì)互相覆蓋,或者產(chǎn)生不連續(xù)的索引。這并不象PHP中的array_merge()函數(shù),后者會(huì) 刪除原有的數(shù)字索引,重新對(duì)索引進(jìn)行編號(hào)。
Example 13-2. append_by_ref
|