note 45059 deleted from function.array-merge by salathe
| From: | salathe@php.net | Date: | Mon, 06 Sep 2021 22:45:52 +0000 |
| Subject: | note 45059 deleted from function.array-merge by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-216896@lists.php.net to get a copy of this message | ||
Note Submitter: bcraigie at bigfoot dot com
----
It would seem that array_merge doesn't do anything when one array is empty (unset):
<?php //$a is unset
$b = array("1" => "x");
$a = array_merge($a, $b});
//$a is still unset.
?>
to fix this omit $a if it is unset:-
<?php
if(!IsSet($a)) {
$a = array_merge($b);
} else {
$a = array_merge($a, $b);
}
?>
I don't know if there's a better way.