note 47597 deleted from function.array-merge by levim
| From: | levim@php.net | Date: | Mon, 24 Feb 2014 22:52:42 +0000 |
| Subject: | note 47597 deleted from function.array-merge by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198674@lists.php.net to get a copy of this message | ||
Note Submitter: Jae
----
This is explained above but may not be exactly clear. If you have two arrays such as:
$Array1 {
[0] => "dog"
}
$Array2 {
[0] => "cat",
[1] => "bird",
[2] => null,
...
[n-1] => null,
[n] => "gator"
}
and you don't want to lose the null values in the final array then do NOT use array_merge.
Instead simply use the + operator.
array_merge($Array1,$Array2) gives:
[0] => "dog",
[1] => "cat",
[2] => "bird",
[3] => "gator"
$Array1 + $Array2 gives:
[0] => "dog",
[1] => "cat",
[2] => "bird",
[3] => null,
...
[n-1] => null,
[3] => "gator"