Thursday, April 21, 2016

[PHP][JavaScript] 用 "=" 賦值時,PHP是複製(copy)物件,JS是參照(reference)物件。

JS:
var $a = ['a','b','c'];
var $b = $a;
$b[1] = 'x';
alert($a[1]);  //印出x

PHP:
$a = array('a','b','c');
$b = $a;
$b[1] = 'x';
echo $a[1];  //印出b

No comments:

Post a Comment