About the management of arrays and memory in PHP
According to the manual, php except object, other types of variables in the assignment, parameter passing, return value is a copy of it
But look at the following test, do not know because the test method is a problem, or if it is not used & by reference, or share the same part of memory, but after changing its elements to actually generate a copy out?
------Solution--------------------
It's not clear what your goal is.
m = 0;
$m = Memory_get_usage ();
$t = array (' id ' = = 1, ' name ' = ' None ');
Echo ' $t occupancy: ', Memory_get_usage ()-$m, Php_eol;
$data = Array ();
Echo ' Empty $data occupy: ', Memory_get_usage ()-$m, Php_eol;
$m = Memory_get_usage ();
for ($i =0; $i <1000; $i + +) {
$data [] = null;
}
echo ' 1000 empty elements $data occupied: ', Memory_get_usage ()-$m, Php_eol;
$data = Array ();
$m = Memory_get_usage ();
for ($i =0; $i <1000; $i + +) {
$data [] = $t;
}
Echo ' 1000 $t elements of $data occupy: ', Memory_get_usage ()-$m, Php_eol;
$data = Array ();
$m = Memory_get_usage ();
for ($i =0; $i <1000; $i + +) {
$data [] = array (' id ' = = 1, ' name ' = ' None ');
}
$data occupancy of ECHO ' 1000 entity elements: ', Memory_get_usage ()-$m, Php_eol;
$t Occupation: 360
Empty $data Occupation: 496
$data occupancy of 1000 empty elements: 84200
$data occupancy of 1000 $t elements: 52104
$data occupancy of 1000 entity elements: 356136
It might be clearer.
------Solution--------------------
Reference:
Of course, that is the surface phenomenon, I want to know how to manage the memory of PHP, there is no official information what, or can only see the source of PHP?
Hash table
------Solution--------------------
PHP variables are copied at the time of writing
Look at this article: http://www.laruence.com/2008/09/19/520.html