array_merge_recursive
| From: | Michiel van Wessem | Date: | Fri, 20 Sep 2002 16:14:01 +0000 |
| Subject: | array_merge_recursive | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-117037@lists.php.net to get a copy of this message | ||
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