Req #48305 [Opn->Fbk]: SORT_VERSION for sort functions
| From: | levim@php.net | Date: | Wed, 30 Apr 2014 22:53:11 +0000 |
| Subject: | Req #48305 [Opn->Fbk]: SORT_VERSION for sort functions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185534@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=48305&edit=1
ID: 48305
Updated by: levim@php.net
Reported by: sean at wdsolutions dot com
Summary: SORT_VERSION for sort functions
-Status: Open
+Status: Feedback
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
-Operating System: Linux
+Operating System: Irrelevant
-PHP Version: 5.2.9
+PHP Version: Any
Block user comment: N
Private report: N
New Comment:
Is this something you are still interested in seeing?
Previous Comments:
------------------------------------------------------------------------
[2009-05-18 12:12:50] a at b dot c dot de
You could use the existing "version_compare" function instead of writing your own. That
would cover the PHP version-numbering convention. Other conventions could be addressed by
hand-written functions, but given the existence of those other conventions a single
"SORT_VERSION" flag wouldn't be sufficient.
------------------------------------------------------------------------
[2009-05-16 18:49:07] sean at wdsolutions dot com
Description:
------------
It would be awesome to have a SORT_VERSION flag for the sort family of functions, whose behavior
would be to sort most common multi-number version strings (with possible support for detecting -cvs,
-rc, -svn, and other suffixes).
For example, SORT_NUMERIC and SORT_STRING both fail to properly sort the following version numbers:
1.2.1
1.2.2
1.2.10
1.20.5
1.22.50
They get sorted as:
1.20.5
1.2.1
1.2.10
1.2.2
1.22.50
Code I used to work around it is below:
Reproduce code:
---------------
function vercmp($a, $b) {
$as = explode('.', $a);
$bs = explode('.', $b);
for ($i = 0, $e = max(count($as), count($bs)); $i != $e; ++$i) {
if ($as[$i] < $bs[$i])
return -1;
elseif ($as[$i] > $bs[$i])
return 1;
}
return 0;
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=48305&edit=1