我有一个存储一些员工对象的数组,即。
var $this->employeeArray = array();
$this->employeeArray[] = $empObjectA;
$this->employeeArray[] = $empObjectB;
...
哪个 Employee 对象具有 id、firstName、lastName 等。我还有一个函数可以搜索具有特定 ID 的员工对象。IE:
public function searchArrayByID($id) {
$targetObject = null;
foreach($this->employeeArray as $e) {
if ($id == $e->id) {
$targetObject = $e;
break;
}
}//foreach
return $targetObject;
}
但是当我这样做时:
$targetEmployee = $this->searchArrayByID(1);
$targetEmployee->firstName = "someOtherName";
并做一个
print_r($this->employeeArray);
数组中的那个对象没有被改变。