ID: 48305
Comment by: a at b dot c dot de
Reported By: sean at wdsolutions dot com
Status: Open
Bug Type: Feature/Change Request
Operating System: Linux
PHP Version: 5.2.9
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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 http://bugs.php.net/?id=48305&edit=1