Re: array_merge_recursive

From: Date: Fri, 20 Sep 2002 16:52:18 +0000
Subject: Re: array_merge_recursive
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-117040@lists.php.net to get a copy of this message
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" <jmvw@wwwcomm.com> To: <php-general@lists.php.net> 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

« previous php.general (#117040) next »