Req #48305 [Fbk->Wfx]: SORT_VERSION for sort functions

From: Date: Thu, 01 May 2014 06:49:31 +0000
Subject: Req #48305 [Fbk->Wfx]: SORT_VERSION for sort functions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185543@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:         nikic@php.net
 Reported by:        sean at wdsolutions dot com
 Summary:            SORT_VERSION for sort functions
-Status:             Feedback
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            *General Issues
 Operating System:   Irrelevant
 PHP Version:        Any
 Block user comment: N
 Private report:     N

 New Comment:

As pointed out by the first comment, this can already be accomplished by passing version_compare to
usort.


Previous Comments:
------------------------------------------------------------------------
[2014-04-30 22:53:11] levim@php.net

Is this something you are still interested in seeing?

------------------------------------------------------------------------
[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


Thread (4 messages)

« previous php.bugs (#185543) next »