array_merge()
| From: | Gerd Terlutter | Date: | Mon, 15 Sep 2003 15:46:43 +0000 |
| Subject: | array_merge() | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-7816@lists.php.net to get a copy of this message | ||
Hi all,
it's not a pear-problem, but a PHP. I have two arrays and wish to add the 2nd to the 1st. This is the code(example) :
$arr=array(0=>array("ID"=>1,"port"=>"HAM",2=>0,3=>5,4=>10),
1=>array("ID"=>2,"port"=>"BRV",2=>0,3=>5,4=>10),
2=>array("ID"=>3,"port"=>"SHX",2=>0,3=>5,4=>10),
3=>array("ID"=>4,"port"=>"NYK",2=>0,3=>5,4=>10),
4=>array("ID"=>5,"port"=>"OAK",2=>0,3=>5,4=>10));
$arr2=array(0=>array("ID"=>6,"port"=>"ANR",2=>0,3=>5,4=>10),
1=>array("ID"=>7,"port"=>"SOU",2=>0,3=>5,4=>10),
2=>array("ID"=>8,"port"=>"HKG",2=>0,3=>5,4=>10),
3=>array("ID"=>9,"port"=>"SIN",2=>0,3=>5,4=>10),
4=>array("ID"=>10,"port"=>"PSD",2=>0,3=>5,4=>10));
array_merge($arr, $arr2);
print_r($arr);
//output :
Array ( [0] => Array ( [ID] => 1 [port] => HAM [2] => 0 [3] => 5 [4] => 10 ) [1] => Array ( [ID] => 2 [port] => BRV [2] => 0 [3] => 5 [4] => 10 ) [2] => Array ( [ID] => 3 [port] => SHX [2] => 0 [3] => 5 [4] => 10 ) [3] => Array ( [ID] => 4 [port] => NYK [2] => 0 [3] => 5 [4] => 10 ) [4] => Array ( [ID] => 5 [port] => OAK [2] => 0 [3] => 5 [4] => 10 ) )
I'll use something like this in a dynamic script and look for a faster method then
foreach($arr2 as $entry)
array_push($arr, $entry);any idea ? -- -------------------------------------------------------- # Gerd Terlutter | Mueller+Blanck Software GmbH # # gerd@MplusB.de | Gutenbergring 38 # # gerd.terlutter@web.de | D-22848 Noderstedt # # tel:0171/6992579 | tel:+49 40 500 171-1 # # Buero:040/500171-17 | fax:+49 40 500 171-71 # --------------------------------------------------------