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

 ID:                 45024
 Updated by:         [email protected]
 Reported by:        tobias at gaszmann dot de
 Summary:            Its not a bug, its a feature, but a problem.
-Status:             Open
+Status:             Bogus
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            *General Issues
 Operating System:   *
 PHP Version:        5.2.6
 Block user comment: N
 Private report:     N

 New Comment:

numeric string keys are converted to integers automatically to avoid
situations where you have $a[1] and $a["1"], this is expected.


Previous Comments:
------------------------------------------------------------------------
[2008-05-16 20:18:20] tobias at gaszmann dot de

Description:
------------
Associative Arrays loose their "string-but-numbers-only-keys" when being
merged.



array_something["34"]="hello 34";

will get lost when being array_merged.



array_something["34_ID"]="hello 34";

will be ok when being array_merged.



I know this is most likely a feature, but it really did threw me off and
took a while to get down to. To me this is an unwanted behavior.



Even more so, as you cannot force the array to remain associative, even
not by "(string)" or settype, as you can see in the demo-code. 



Thank you!

Tobias Gassmann



Reproduce code:
---------------
$array_one=array();

$array_one["one"]   = "Database-Entry with UID='one'";

$array_one["2_uid"] = "Database-Entry with UID='2_uid'";

$array_one["ID_3"]  = "Database-Entry with UID='ID_3'";

print_r($array_one);



$array_two=array();

$array_two["four"]  = "Database-Entry with UID='four'";

$array_two["5"]     = "Database-Entry with UID='5'";

$string_six="6";

$array_two["$string_six"] = "Database-Entry with UID='6'";

$string_seven="7";

settype($string_seven,"string");

$array_two["$string_seven"] = "Database-Entry with UID='7'";

$array_two["ID_8"]  = "Database-Entry with UID='ID_8'";

print_r($array_two);



$array_three = array_merge($array_one,$array_two);

print_r($array_three);



Expected result:
----------------
I would have expected for all keys to remain what they are. 

Actual result:
--------------
The keys "5", "6" and "7" got lost, although I declared them as strings.


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



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

Reply via email to