|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-06-08 19:35 UTC] graced at monroe dot wednet dot edu
Description: ------------ See: bug #28435 array_count_values() problem http://www.php.net/manual/en/language.types.array.php array_count_values() casts numeric strings (i.e. "72") to integers (72). This is correct (although annoying) behavior as described at http://www.php.net/manual/en/language.types.array.php, except for one catch. The documentation states (emphasis mine) "If a key is the standard representation of an integer, it will be interpreted as such (i.e. "8" will be interpreted as 8, ***while "08" will be interpreted as "08"***). However, array_count_values() will strip the leading zeroes and turn those strings into integers, which causes errors in code later on when (string) 8 is compared against (string) "08" and the comparison fails. Reproduce code: --------------- <?php var_dump(array_count_values(array("012345"))); Expected result: ---------------- array(1) { ["012345"]=> int(1) } Actual result: -------------- array(1) { [12345]=> int(1) } PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 06:00:01 2025 UTC |
For what it's worth, *this* works: var_dump(array("012345" => 'yay')); array(1) { ["012345"]=> string(3) "yay" } so it looks like it's an issue with array_count_values() itself and not something at a deeper level.