[nycphp-talk] Best way to copy array by value
Daniel Convissor
danielc at analysisandsolutions.com
Sun Feb 25 17:39:50 EST 2007
Aaron:
On Sun, Feb 25, 2007 at 03:47:45PM -0500, Aaron Fischer wrote:
> I need to copy an array by value, not by reference. Is there a best
> way to do this? Right now I found serialize/unserialize which seems
> to do the trick.
What ARE you talking about? Copying by value is the default behavior in
PHP.
INPUT:
$a1 = array('a', 'b');
$a2 = $a1;
$a1[0] = 'changed';
print_r($a1);
print_r($a2);
OUTPUT:
Array
(
[0] => changed
[1] => b
)
Array
(
[0] => a
[1] => b
)
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
More information about the talk
mailing list