【发布时间】:2010-05-28 15:37:59
【问题描述】:
根据以下示例,PHP 中的育儿功能如何正确完成? 我能否确保在每次 addArray 调用时我的数组不会被覆盖并且数组中的先前值会丢失?
function arraybase() {
$this->array = new ArrayObject();
return $this;
}
function addArray($value) {
parent::$this->arraybase();
$this->array->append($value);
return $this;
}
$this->addArray('1')->addArray('2')->addArray('3');
// outputs:
Array
(
[0] => 3
)
【问题讨论】:
-
数组 ([0] => 1, [1] => 2, [3] => 3);