note 37056 deleted from function.array-merge by levim
| From: | levim@php.net | Date: | Mon, 24 Feb 2014 22:51:47 +0000 |
| Subject: | note 37056 deleted from function.array-merge by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198671@lists.php.net to get a copy of this message | ||
Note Submitter:
----
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.