php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25470 array_merge converts indexes differently in 4.3.3
Submitted: 2003-09-10 11:53 UTC Modified: 2003-09-24 09:37 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bmansion at mamasam dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.3 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
44 - 17 = ?
Subscribe to this entry?

 
 [2003-09-10 11:53 UTC] bmansion at mamasam dot com
Description:
------------
When the index in the array is a string like "1234567890", I mean containing only figures, array_merge will convert it to an int and change the index by resetting the value.

2 options:
Make our own array_merge function.

PHP Team fix array_merge so that it keep track of the index type.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-24 07:13 UTC] f dot berger at 21torr dot com
The Category should be changed and the bug should be retitled, because this is a general bug, not related to PEAR, and not related to HTML_QuickForm.

Problem I have:
  $ar = array ('-999'=>'a',0=>'b',1=>'c');
  $ar2 = array ('x'=>'x','y'=>'y','z'=>'z');
  print_r(array_merge($ar,$ar2));
results in a version prior to 4.3.3 to
  Array ( [-999] => c [0] => b [1] => a [x] => x [y] => y [z] => z )
in version 4.3.3 to
   [0] => a [1] => b [2] => c [x] => x [y] => y [z] => z )
 [2003-09-24 07:28 UTC] bmansion at mamasam dot com
Changing bug category as requested by f.berger.
 [2003-09-24 09:37 UTC] sniper@php.net
RTFM: "Don't forget that numeric keys will be renumbered!"

"-999" is numeric


 [2003-10-02 05:48 UTC] f dot berger at 21torr dot com
in regards to RTFM:

as you see in the example, it was written as '-999', means it is a string!

Furthermore, array_merge is behaving correctly (not converting strings containing only numbers to numbers..) in earlier version

what for example if my key NEEDS to be '0497121' (this is my phone-number-prefix), in this case i need the leading 0, and I don't need it renumbered, because for my context this is a string, not an int.

The Documentation is correct on ints, the problem is that a string only containing numbers will be converted to an int before merging the arrays (which is a new behaviour, and in my Eye bogus)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 00:01:27 2024 UTC