<?php
$arr = array(1,2,3,4,5,6);
foreach ($arr as &$val){
$val = 'x';
$new[] = $val;
}
print_r($new); //赋值
echo "<br>/n";
print_r($arr); //引用
?>
<?php
class A{
static public $WHAT='aa';
private $a;
function __construct(){
$this->hello();
}
function seta($val){
$this->a = $val;
}
function geta(){
return $this->a;
}
function hello(){
echo "hello world";
}
}
$a = new A();
$a->seta("hello8");
echo $a->geta(); //output:hello8
echo "<br />";
$b = $a;
$b->seta("ttttaaa");
echo $b->geta(); //output:ttttaaa
echo "<br />";
$c = clone $a;
echo $c->geta();
//output:ttttaaa 为什么不是hello8呢,原因是$b与$a是对象的引用,因此当$b中的seta方法给$a改变值时$a 所new出来的对象的值也变化了所以当$c复制$a对象时就变成了这种情况了