note 78838 deleted from function.version-compare by cmb
| From: | cmb@php.net | Date: | Mon, 26 Oct 2020 16:11:26 +0000 |
| Subject: | note 78838 deleted from function.version-compare by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215654@lists.php.net to get a copy of this message | ||
Note Submitter: Jonathon dot Reinhart at gmail dot com
----
I know this is somewhat incomplete, but it did a fair enough job for what I needed. I was writing
some code that needed done immediately on a server that was to be upgraded some time in the future.
Here is a quick replacement for version_compare (without the use of the operator argument). Feel
free to add to this / complete it.
<?php
function version_compare2($version1, $version2)
{
$v1 = explode('.',$version1);
$v2 = explode('.',$version2);
if ($v1[0] > $v2[0])
$ret = 1;
else if ($v1[0] < $v2[0])
$ret = -1;
else // Major ver are =
{
if ($v1[1] > $v2[1])
$ret = 1;
else if ($v1[1] < $v2[1])
$ret = -1;
else // Minor ver are =
{
if ($v1[2] > $v2[2])
$ret = 1;
else if ($v1[2] < $v2[2])
$ret = -1;
else
$ret = 0;
}
}
return $ret;
}
?>