note 37056 added to function.array-merge

From: Date: Sat, 01 Nov 2003 03:08:42 +0000
Subject: note 37056 added to function.array-merge
Groups: php.notes 
Request: Send a blank email to php-notes+get-59610@lists.php.net to get a copy of this message
In all PHP 4 versions the above function deals gracefully with paramaters which are NOT arrays(). So if you pass a string or number it will be automagically converted to an one-element array as described in the manual section about Types and "implicit typecasting". So if you ever happen to put an empty/unset variable (NULL value) as parameter, array_merge() will still collapse the other arrays as intended. From PHP5beta2 on this behaviour changed, and PHP will correctly issue a E_WARNING message, whenever one of the paramters isn't an array. So if you ever happen to be uncertain about the contents of a variable passed as parameter to array_merge() you should use explicit typecasting: $a = array(1, 2, 3); $b = 4; #-- beware: this is no array! $result = array_merge( (array)$a, (array)$b, ... ); This way $result still would get == array(1, 2, 3, 4); where otherwise the parameters would get rejected with the warning message telling you so. ---- Manual Page -- http://www.php.net/manual/en/function.array-merge.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37056 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37056&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37056&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#59610) next »