[SOLVED] Array numeric index as string

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

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

[SOLVED] Array numeric index as string

Post by anjanesh »

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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Cant believe I missed this !
Thanks
Post Reply