metawidget: A platypus looking pensive. (Default)
[personal profile] metawidget
How ugly is this approach to making a copy of an array that moves only values, not references?

$copy_of_array = unserialize(serialize($multidimensional_array));

I feel a little dirty... assuming I'm not too worried about efficiency, should I?

Date: 2006-08-21 01:00 pm (UTC)
From: [identity profile] v0idnull.livejournal.com

$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

Profile

metawidget: A platypus looking pensive. (Default)
metawidget
Page generated Jan. 16th, 2026 06:40 pm

June 2025

S M T W T F S
123 4567
89 1011121314
15 161718192021
22 232425 262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Powered by Dreamwidth Studios