note 47597 added to function.array-merge
| From: | Jae at osu1 dot php dot net | Date: | Mon, 22 Nov 2004 15:17:52 +0000 |
| Subject: | note 47597 added to function.array-merge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-80872@lists.php.net to get a copy of this message | ||
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"
----
Manual Page -- http://www.php.net/manual/en/function.array-merge.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47597
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47597&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47597&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47597&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47597&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47597&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47597&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47597&report=yes
Search -- http://master.php.net/manage/user-notes.php