ID: 28435
User updated by: ofirin at yahoo dot com
Reported By: ofirin at yahoo dot com
-Status: Open
+Status: Closed
Bug Type: Arrays related
Operating System: Any
PHP Version: 4CVS-2004-05-18 (stable)
New Comment:
Ok, I think you're right, we all should be looking forward working with
php5, rather than trying to fix old bugs in php4.
Previous Comments:
------------------------------------------------------------------------
[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