Bug #764 Updated: ksort mixes the implicit variable types and result is unexpected.
| From: | Bug Database | Date: | Mon, 21 Sep 1998 20:03:40 +0000 |
| Subject: | Bug #764 Updated: ksort mixes the implicit variable types and result is unexpected. | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-1335@lists.php.net to get a copy of this message | ||
ID: 764
User Update by: libs@cybercable.tm.fr
Old-Status: Closed
Status: Open
Old-Bug Type: Misbehaving function
Bug Type: Feature/Change Request
Description: ksort mixes the implicit variable types and result is unexpected.
<?
$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]
Full Bug description available at: http://ca.php.net/bugs.php3?id=764
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net