|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-09-28 08:19 UTC] nick at macaw dot demon dot co dot uk
Found in 4.0.7RC2 but probably present before. Array merge changes keys that are string-numeric. e.g.
<?
$arr1 = array('1'=>'one', '2'=>'two');
$arr2 = array('a'=>'all');
print_r(array_merge($arr1, $arr2));
?>
gives:
Array ( [0] => one [1] => two [a] => all )
A workaround kludge is to prefix string-numeric keys with a letter.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 06:00:01 2025 UTC |
This is not a bug, but a feature. All string indexes are converted to numbers if possible, even like this: <?php $a = array ('4' => "test"); print_r ($a); ?> will show: Array ( [4] => test ) Making it bogus<? It's a bug ! Look this : <? $tbl_1 = array("025" => "hello 025", "050" => "hello 050", "120" => "hello 120"); $tbl_2 = array("010" => "hello 010", "130" => "hello 130"); ?> Gives : Array ( [025] => hello 025 [050] => hello 050 [0] => hello 120 [010] => hello 010 [1] => hello 130 ) Why '[1] => hello 130' and not '[130] => hello 130' ?