Re: note 9465 added to array_push

From: Date: Sun, 05 Nov 2000 02:58:13 +0000
Subject: Re: note 9465 added to array_push
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-7387@lists.php.net to get a copy of this message
howardh@telus.net writes: > array_push in PHP 4.0.3pl1 does not properly push array values onto > another array. Instead of appending all of the array values onto > the first array, the entire second array is added under a single new > key entry. > > Eg: array_push($array1,$array2) > > is the same as doing $array1["newkey"] = $array2 > > http://www.php.net/manual/function.array-push.php Thanks for the note, but A) that's a bug report, not a submission for text to be added to the manual, and B) it's working correctly. The reason is that the purpose of array_push() is to add one variable onto the end of an array. It should always behave the same no matter what kind of variable you're adding; i.e. it should pretty much do the same thing as $array[] = $newval, as noted. I think you probably want array_merge(), which is intended to to what you seem to be looking for. Cheers, Torben -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.notes (#7387) next »