ID:          13478
 Comment by:  dseo at premiant dot net
 Reported By: nick at macaw dot demon dot co dot uk
 Status:      Bogus
 Bug Type:    Arrays related
 PHP Version: 4.0.6
 New Comment:

I agree with comment above. I have data coming in from database, and I
have to use mixed keys with string and integer, and the integer will
skip some numbers.

If I bring 'M', 'W', 1, 5, 11, 8 as keys, it will mix up it's order
where I have to sort the numbers.  In database, I can pre-sort them
because it will sort 1, 11, 5, 8, so on.

Is there any way I can merge them without changing the key?


Previous Comments:
------------------------------------------------------------------------

[2003-11-25 07:30:29] partage_php at yahoo dot fr

<?

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' ?

------------------------------------------------------------------------

[2001-09-28 08:28:14] [EMAIL PROTECTED]

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

------------------------------------------------------------------------

[2001-09-28 08:19:02] 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. 


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=13478&edit=1

Reply via email to