<?php
class User{
public $id;
public $name;
function __construct($id, $name) {
$this->id = $id;
$this->name = $name;
}
}
$arrUser = [
new User(1,’zc’),
new User(2,’xhd’),
new User(3,’pp’),
new User(4,’zl’),
];
function processObj($arr)
{
foreach($arr as $item) {
$item->name .= ‘_man’;
}
}
function processArr($arr)
{
foreach($arr as $item) {
$item[‘b’] .= ‘_man’;
}
}
$arrTest = [
[‘a’ => 1, ‘b’ => 2],
[‘a’ => 3, ‘b’ => 4],
[‘a’ => 5, ‘b’ => 6],
];
processObj($arrUser);
var_dump($arrUser);
processArr($arrTest);
var_dump($arrTest);
从输出结果 可以看到$arrUser内容发生了改变 $arrTest内容没有改变