ID: 28435 Comment by: alexis dot bosson at medias dot cnes dot fr Reported By: ofirin at yahoo dot com Status: Closed Bug Type: Arrays related Operating System: Any PHP Version: 4CVS-2004-05-18 (stable) New Comment:
As said in : - bug #9307 - bug #21918 - bug #22201 - and documentation of arrays : http://www.php.net/manual/en/language.types.array.php " 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"). " So the array_count_values must cast the integers contained in strings to integers. Actually, with standard PHP behavior, it's impossible to access directly to those array elements which keys are strings containing integers, as said in comment of June 18 Previous Comments: ------------------------------------------------------------------------ [2004-06-21 17:50:47] ofirin at yahoo dot com Ok, I think you're right, we all should be looking forward working with php5, rather than trying to fix old bugs in php4. ------------------------------------------------------------------------ [2004-06-21 11:31:59] vladb at pseudo-infinity dot ro The php5 result seems more accurate than the php4 one. You got strings in the $books array, no? Changing this in php4 may break some code out there so maybe it'd be best to just mention it as a 4-5 inconsistency. ------------------------------------------------------------------------ [2004-06-18 14:24:41] programmer at bardware dot de I noticed this problem with PHP5 RC2 on a Win2k box as an Apache2-module. I have some HMTL-Checkboxes and on the server side want to check the selected values. My checkboxes are equally named name="choice2[]" what lets PHP generate an array $_POST["choice2"][0] $_POST["choice2"][1] $_POST["choice2"][2] etc. according to the selected values. Each checkbox has it's unique value attribute. To test for a certain value I "reverse" this array with $arrTmp=array_count_values($_POST["choice2"]); I now want to access $arrTmp[1] to check if the checkbox with the attribute value="1" was selected. The respective value was - if selected - 1, otherwise it's not existent in the $_POST["choice2"]-Array. This did not work. $arrTmp["1"] didn't work either. It was no way possible to access a member of the array. The other poster mentioned the indexes are generated as strings, I want to point they cannot be accessed at all. It worked best on PHP 4.3.6 Best, Bernhard ------------------------------------------------------------------------ [2004-05-18 19:04:43] ofirin at yahoo dot com Description: ------------ I don't know if this is a php5 or php4 bug, but I'm sure something's wrong here. Whenever in php5 I do an array_count_values() on an array that contains numeric values as strings the result array uses string keys instead of the numeric values as indexes. This doesn't happen in php4. I don't know what behaivor is correct. I'm using the latest cvs versions of both php4 and php5 btw. Reproduce code: --------------- <?php $books = Array('10', '3', '6', '10'); $quantities = array_count_values($books); var_dump($books); var_dump($quantities); ?> Expected result: ---------------- This is what happens in php4: array(4) { [0]=> string(2) "10" [1]=> string(1) "3" [2]=> string(1) "6" [3]=> string(2) "10" } array(3) { [10]=> int(2) [3]=> int(1) [6]=> int(1) } Actual result: -------------- This is what happens if php5: array(4) { [0]=> string(2) "10" [1]=> string(1) "3" [2]=> string(1) "6" [3]=> string(2) "10" } array(3) { ["10"]=> int(2) ["3"]=> int(1) ["6"]=> int(1) } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=28435&edit=1