|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-05-18 12:12 UTC] a at b dot c dot de
[2014-04-30 22:53 UTC] levim@php.net
-Status: Open
+Status: Feedback
-Package: Feature/Change Request
+Package: *General Issues
-Operating System: Linux
+Operating System: Irrelevant
-PHP Version: 5.2.9
+PHP Version: Any
[2014-04-30 22:53 UTC] levim@php.net
[2014-05-01 06:49 UTC] nikic@php.net
-Status: Feedback
+Status: Wont fix
[2014-05-01 06:49 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 11:00:02 2025 UTC |
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; }