PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Sun Aug 20, 2006 5:02 am
Code: Select all
<?php
$a = array('1' => 'one', '2' => 'two');
$b = array('a' => 'A', 'b' => 'B');
$c = array_merge($a, $b);
print_r($c);
?>
Output is
Array ( [0] => one [1] => two [a] => A => B )
What I want is Array ( [1] => one [2] => two [a] => A => B )
Is there a way to accomplish this ?
[I dont want to change my $a to $a = array('01' => 'one', '02' => 'two'); ]
Thanks
Last edited by
anjanesh on Sun Aug 20, 2006 6:34 am, edited 1 time in total.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sun Aug 20, 2006 5:21 am
http://de2.php.net/array_merge
If you want to completely preserve the arrays and just want to append them to each other, use the + operator
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Sun Aug 20, 2006 6:33 am
Cant believe I missed this !
Thanks