note 124055 deleted from function.array-merge by salathe

From: Date: Mon, 06 Sep 2021 22:48:07 +0000
Subject: note 124055 deleted from function.array-merge by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-216917@lists.php.net to get a copy of this message
Note Submitter: makjoybd [at] gmail [dot] com ---- $a = array(1,2,3); // an array $b = 5; // anything but not an array $c = array_merge($a, $b); // shows a PHP warning: Argument #2 is not an array var_dump($c); // output as NULL // now merge in reverse order $d = array_merge($b, $a); // shows a PHP warning: Argument #1 is not an array var_dump($d); // output as NULL NOTE: For any operation that relies on the previous array merge operation it is highly necessary to check the arguments as well as the result of the merge are arrays before continuing as the warning would not stop the operation and this might result in data loss and what not... and this should also be stated in the .documentation. Example #3 somewhat started to demonstrate this but used type casting which made this irrelevant to this matter.

« previous php.notes (#216917) next »