semi-dirty PHP trick?
Aug. 21st, 2006 12:20 amHow ugly is this approach to making a copy of an array that moves only values, not references?
I feel a little dirty... assuming I'm not too worried about efficiency, should I?
$copy_of_array = unserialize(serialize($multidimensional_array));I feel a little dirty... assuming I'm not too worried about efficiency, should I?
no subject
Date: 2006-08-21 01:00 pm (UTC)$a1[0] = 'hello world';
$a2 = $a1;
$a2[0] = 'foo bar';
echo $a1[0].':'.$a2[0]; // hello world:foo bar
$a2 =& $a1;
$a2[0] = 'foo bar';
echo $a1[0].':'.$a2[0]; // foo bar:foo bar
the = operator means assignment. =& operator means reference.
ecmascript (which is what actionscript/javascript are dervitives of), can be wierd when it comes to references.
var i;
var x;
i = x; // i & x are two seperate variables.
var i;
i = some.global.scope.object; // i is a reference of that object