Page 1 of 1

[SOLVED] Array numeric index as string

Posted: Sun Aug 20, 2006 5:02 am
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

Posted: Sun Aug 20, 2006 5:21 am
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

Posted: Sun Aug 20, 2006 6:33 am
by anjanesh
Cant believe I missed this !
Thanks