200806180118PHP Reference 測試

看完 PHP: References Explained - Manual 順手做了幾個測試︰

1.

$v = 1;
$r =& $v;
$v = 2;
echo "$v, $r";  // 會印 2, 2


2.

$v = 1;
$r =& $v;
unset($v);
echo "$v, $r";  // 會印 , 1


3.

$v = 1;
$r =& $v;
unset($r);
echo "$v, $r";  // 會印 1,


4.

$v = 1;
$r =& $v;
unset($v);
$v = 2;
echo "$v, $r";  // 會印 2, 1


5.

$arr = array(1, 2, 3);
foreach($arr as $v)
    unset($v);
print_r($arr);  // 會印 Array ( [0] => 1 [1] => 2 [2] => 3 )


6.
$arr = array(1, 2, 3);
foreach($arr as &$r)
    unset($r);
print_r($arr);  // 會印 Array ( [0] => 1 [1] => 2 [2] => 3 )

 

延伸 PHP array [ ] reference
回應
Google 站內搜尋
BloggerAds
累積 | 今日
loading......
    沒有新回應!





Powered by Xuite