note 106037 added to function.array-merge

From: Date: Tue, 04 Oct 2011 23:42:14 +0000
Subject: note 106037 added to function.array-merge
Groups: php.notes 
Request: Send a blank email to php-notes+get-183638@lists.php.net to get a copy of this message
I keep seeing posts for people looking for a function to replace numeric keys. No function is required for this, it is default behavior if the + operator: $a=array(1=>"one", "two"=>2); $b=array(1=>"two", "two"=>1, 3=>"three", "four"=>4); print_r($a+$b); Array ( [1] => one [two] => 2 [3] => three [four] => 4 ) How this works: The + operator only adds unique keys to the resulting array. By making the replacements the first argument, they naturally always replace the keys from the second argument, numeric or not! =) ---- Server IP: 69.147.83.197 Probable Submitter: 96.50.58.182 ---- Manual Page -- http://www.php.net/manual/en/function.array-merge.php Edit -- https://master.php.net/note/edit/106037 Del: integrated -- https://master.php.net/note/delete/106037/integrated Del: useless -- https://master.php.net/note/delete/106037/useless Del: bad code -- https://master.php.net/note/delete/106037/bad+code Del: spam -- https://master.php.net/note/delete/106037/spam Del: non-english -- https://master.php.net/note/delete/106037/non-english Del: in docs -- https://master.php.net/note/delete/106037/in+docs Del: other reasons-- https://master.php.net/note/delete/106037 Reject -- https://master.php.net/note/reject/106037 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183638) next »