|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-05-18 19:04 UTC] 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)
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 19:00:01 2025 UTC |
Why is this bug closed? I am now experiencing the same problem with 5.0.1. The array from array_count_values appears normal with vardump, but there is no way to access the elements; neither as arrayname["2"] nor arrayname[2]. This worked fine with 4.3.x. vardump of result from array_count_values array(5) { ["3"]=> int(2) ["2"]=> int(1) ["1"]=> int(1) ["0"]=> int(1) [0]=> int(0) } It looks like you'd be able to access the value with arrayname["2"], but you can't!