note 37056 modified in function.array-merge by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 13:58:53 +0000 |
| Subject: | note 37056 modified in function.array-merge by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-80070@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:
<?php
$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.
--was--
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.
http://php.net/manual/en/function.array-merge.php