Bug #765: new kusort() function (or similar)

From: Date: Tue, 22 Sep 1998 00:32:52 +0000
Subject: Bug #765: new kusort() function (or similar)
Groups: php.dev 
Request: Send a blank email to php-dev+get-1344@lists.php.net to get a copy of this message
From: libs@cybercable.tm.fr Operating system: Linux (irrelevant) PHP version: 3.0.3 PHP Bug Type: Feature/Change Request Bug description: new kusort() function (or similar) I'd be delighted if a new function similar to ksort would appear in PHP3. 1/The requested functionality would be the following one: 1.1/Consider an array: $toto["001"]="a"; $toto["010"]="c"; $toto["100"]="d"; $toto["002"]="b"; $toto["110"]="e"; 1.2/Sorting this array on its key with the requested function would give: key : value 001 : a 002 : b 010 : c 100 : d 110 : e 1.3/Due to variable typing, ksort behaves differently and sorts this way: key : value 010 : c 100 : d 110 : e 001 : a 002 : b 1.4/There is no practical way of getting the requested functionality with the existing functions. Prepending zero or appending a dot work, of course, but it lacks elegance, especially when you have to strip the zero or the dot afterwards for use in the rest of the script. 2/Suggested ways of achieving the requested functionality. 2.1/ kusort() function. A kusort() function, modeled after ksort like usort is modeled after sort. This would be the most versatile solution. 2.2/ kasort() function. This key sort would assume that we deal with an associative array and all keys are strings. It would not change the types of keys inside the array, just the comparisons in the sorting algorithm. It is less versatile but just what I need, so I assume other people will find it useful too. 2.3/ Add an optionnal argument to ksort() for type of comparison. Like so: ksort($array, "integer") or ksort($array, "string") 3/ Conclusion. Coders are choosers. Anything would make me happy, with a preference for kasort() I failed to be concise, but I hope I managed to be clear. -- 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

« previous php.dev (#1344) next »