note 75268 added to function.array-merge

From: Date: Mon, 21 May 2007 12:05:00 +0000
Subject: note 75268 added to function.array-merge
Groups: php.notes 
Request: Send a blank email to php-notes+get-126789@lists.php.net to get a copy of this message
For asteddy at tin dot it and others who are trying to merge arrays and keep the keys, don't forget the simple + operator. Using the array_merge_keys() function (with a small mod to deal with multiple arguments), provides no difference in output as compared to +. <?php $a = array(-1 => 'minus 1'); $b = array(0 => 'nought'); $c = array(0 => 'nought'); var_export(array_merge_keys($a,$b)); var_export($a + $b); var_export(array_merge_keys($a,$b,$c)); var_export($a + $b + $c); ?> results in ... array ( -1 => 'minus 1', 0 => 'nought',) array ( -1 => 'minus 1', 0 => 'nought',) array ( -1 => 'minus 1', 0 => 'nought',) array ( -1 => 'minus 1', 0 => 'nought',) ---- Server IP: 87.124.64.96 Probable Submitter: 83.104.121.66 ---- Manual Page -- http://www.php.net/manual/en/function.array-merge.php Edit -- https://master.php.net/note/edit/75268 Del: integrated -- https://master.php.net/note/delete/75268/integrated Del: useless -- https://master.php.net/note/delete/75268/useless Del: bad code -- https://master.php.net/note/delete/75268/bad+code Del: spam -- https://master.php.net/note/delete/75268/spam Del: non-english -- https://master.php.net/note/delete/75268/non-english Del: in docs -- https://master.php.net/note/delete/75268/in+docs Del: other reasons-- https://master.php.net/note/delete/75268 Reject -- https://master.php.net/note/reject/75268 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#126789) next »