Skip to content

Instantly share code, notes, and snippets.

@xiangyuan
Created August 6, 2012 04:05
Show Gist options
  • Save xiangyuan/3270114 to your computer and use it in GitHub Desktop.
Save xiangyuan/3270114 to your computer and use it in GitHub Desktop.
php数据覆值copy与reference
PHP array assignment (PHP array assignment is copy by value)
$a = array('a', 'b', 'c');
$a2 = $a;
上面的直接覆值是一种copy机制,会产生两个不同的数组供使用
A duplicate copy of the array (copy by value) is made
Change in one array have no impact on other
$a = array("original");
$b = $a;
$a[0] = "new"; // $b[0] will remain as "original"
下面引用是指向同一个数组对象,会相互影响。
To copy PHP array by reference
$a3 = &$a; # A variable alias. Changes impact both $a and $a3
require 'file';//如果文件不存在时会出现错误
include 'file';//如果文件不存在时不会出现错误,只会是警告
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment