(PECL pthreads >= 2.0.0)
Threaded::merge — 操作
將數(shù)據(jù)合并到當(dāng)前對(duì)象
from
要合并的數(shù)據(jù)
overwrite
如果現(xiàn)有對(duì)象已經(jīng)存在同鍵的數(shù)據(jù),是否覆蓋。默認(rèn)為 true
成功時(shí)返回 true
, 或者在失敗時(shí)返回 false
。
示例 #1 合并數(shù)據(jù)到對(duì)象的屬性表
<?php
$array = [];
while (count($array) < 10)
$array[] = count($array);
$stdClass = new stdClass();
$stdClass->foo = "foo";
$stdClass->bar = "bar";
$stdClass->baz = "baz";
$safe = new Threaded();
$safe->merge($array);
$safe->merge($stdClass);
var_dump($safe);
?>
以上例程會(huì)輸出:
object(Threaded)#2 (13) { ["0"]=> int(0) ["1"]=> int(1) ["2"]=> int(2) ["3"]=> int(3) ["4"]=> int(4) ["5"]=> int(5) ["6"]=> int(6) ["7"]=> int(7) ["8"]=> int(8) ["9"]=> int(9) ["foo"]=> string(3) "foo" ["bar"]=> string(3) "bar" ["baz"]=> string(3) "baz" }