定義:用不一樣的名字訪問同一變量內容oop
$a = 1; $b = $a;
$a = 1; $b = &$a;
$data = ['a', 'b', 'c']; foreach ($data as $key => $val) { $val = &$data[$key]; print_r($data); } /* loop_1 $key = 0 $val = 'a' $val = &$data[0] =>'a' (此時$val與$data[0]指向同一地址) $data = ['a','b','c']; loop_2 $key = 1 $val = 'b' => $data[0] = 'b' ($data[0]與$val地址相同,$val改變,$data[0]的值也發生改變) $val = &$data[1] => $val = 'b'($val地址再次發生改變,與$data[1]相同) $data = ['b','b','c']; loop_3 $key = 2 $val = 'c' => $data[1] = 'c'($data[1]與$val地址相同,$val改變,$data[1]的值也發生改變) $val = &$data[2] => $val =>'c'($val地址再次發生改變,與$data[2]相同) $data = ['b','c','c']; */