[nycphp-talk] Best way to copy array by value
inforequest
1j0lkq002 at sneakemail.com
Sun Feb 25 18:43:48 EST 2007
Daniel Convissor danielc-at-analysisandsolutions.com |nyphp dev/internal
group use| wrote:
>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
>
>
>
That Dan's just a straight shooter with management written all over him ;-)
More information about the talk
mailing list