Ahh I see what you mean. Yes that doesn't seem right does it. The function is passing the parameters by reference and affecting them as well as the return value. I don't have a solution for this apart from just being conscious of it and setting the unmodified arrays to new variables before using the function.. or rolling your own merger function. :-\ -Kevin
----- Original Message ----- From: "Michiel van Wessem" <[EMAIL PROTECTED]> To: "Kevin Stone" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Friday, September 20, 2002 10:52 AM Subject: Re: [PHP] array_merge_recursive > Hello Kevin, > > Yes, and that's the good part. The bad part is that $a is affected (try > print_r($a)). I don't think it should be. > > Michiel > > At 12:41 PM 9/20/2002, Kevin Stone wrote: > > >Worked fine for me.. > ><?phpecho "<pre>";print_r($r);echo "</pre>";?>-----------Array > >( > > [k] => Array > > ( > > [0] => a1 > > [1] => b1 > > ) > > > >) > >-----------Access the merged array with with $r['k']; with values at > >$r['k'][0] and $r['k'][1]. Is this not what you wanted? > >-Kevin > > > >----- Original Message ----- > >From: "Michiel van Wessem" <[EMAIL PROTECTED]> > >To: <[EMAIL PROTECTED]> > >Sent: Friday, September 20, 2002 10:14 AM > >Subject: [PHP] array_merge_recursive > > > > > > > Hello! > > > > > > I'm fairly new to PHP and absolutely new to this mailing list. > > > > > > I subscribed and I'm writing because I observed some strange behavior with > > > array_merge_recursive(). I'm using PHP version 4.1.2. Please look at the > > > following code: > > > > > > $a = array('k' => array('a1')); > > > $b = array('k' => array('b1')); > > > $r = array_merge_recursive($a, $b); > > > echo count($a['k']), '<br>'; > > > echo count($b['k']), '<br>'; > > > > > > This will print > > > 2 > > > 1 > > > > > > Apparently $a['k'] has been merged with $b['k'] and $a['k'] has been set > >to > > > the resulting two-element array. I did not expect this behavior: I > >expected > > > the function to make a new array, which contains both 'a1' and 'b1'. Only > > > $r['k'] should refer to this new array. > > > > > > Otherwise, in my opinion, array_merge_recursive should not return a value, > > > just modify the first argument. > > > > > > Should I file a bug report about this? > > > > > > Thank you, > > > > > > Michiel van Wessem > > > > > > > > > Network Administrator > > > > > > > > > > > >--------------------------------------------------------------------------- - > >---- > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > >--- > >Incoming mail is certified Virus Free. > >Checked by AVG anti-virus system (http://www.grisoft.com). > >Version: 6.0.385 / Virus Database: 217 - Release Date: 9/4/2002 > > Network Administrator > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php