note 48902 deleted from function.array-merge by cmb
| From: | cmb@php.net | Date: | Sun, 29 Sep 2019 07:29:08 +0000 |
| Subject: | note 48902 deleted from function.array-merge by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212396@lists.php.net to get a copy of this message | ||
Note Submitter: nospam at veganismus dot ch
----
Someone posted a function with the note:
"if u need to overlay a array that holds defaultvalues with another that keeps the relevant
data"
<?
//about twice as fast but the result is the same.
//note: the sorting will be messed up!
function array_overlay($skel, $arr) {
return $arr+$skel;
}
//example:
$a = array("zero","one","two");
$a = array_overlay($a,array(1=>"alpha",2=>NULL));
var_dump($a);
/* NULL is ignored so the output is:
array(3) {
[1]=>
string(5) "alpha"
[0]=>
string(4) "zero"
[2]=>
string(3) "two"
}
*/
?>