|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[1998-09-21 16:07 UTC] zeev
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 16:00:01 2025 UTC |
<? $toto["001"]="a"; $toto["010"]="c"; $toto[(string)"100"]="d"; $toto["002"]="b"; $toto["110"]="e"; ksort($toto); for(reset($toto); $test = key($toto); next($toto)) { echo ($test." (".gettype($test).") : ".$toto[$test]."<BR>\n"); }; ?> gives 100 (integer) : d<BR> 110 (integer) : e<BR> 001 (string) : a<BR> 002 (string) : b<BR> 010 (string) : c<BR> instead of : 001 (whatever) : a<BR> 002 (whatever) : b<BR> 010 (whatever) : c<BR> 100 (whatever) : d<BR> 110 (whatever) : e<BR> It is agreed that it is not a bug, but the intended functionality is still not available. To make it available at some later time, I would suggest putting either kasort() or kusort() in some TODO list. By kasort() I mean a variation of ksort() which only considers the string value in the sorting comparisons. It wouldn't have to change the types of keys inside the array, just sort them in another way. By kusort() I mean to do something like: function cmp($a,$b) { if($a==$b) return 0; return ((string)$a>(string)$b) ? 1:-1; } kusort($toto, cmp): [config irrelevant]