Created
June 22, 2020 13:18
-
-
Save msztorc/b125cec59d5ac9854b52362a111b2585 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ver_compare($v1, $v2) { | |
function fversion($v) { | |
$c = substr_count($v, '.'); | |
switch($c) { | |
case 0: $v .= '.0.0'; break; | |
case 1: $v .= '.0'; break; | |
} | |
$v = array_map(function($x){return (!is_numeric($x) && $x !== '.') ? (ord($x)) : $x;},str_split($v)); | |
return floatval(preg_replace('/\./', '', implode($v), 1)); | |
} | |
$_v1 = fversion($v1); | |
$_v2 = fversion($v2); | |
if ($_v1 > $_v2) | |
return $v1; | |
else | |
return $v2; | |
} | |
$v1 = '0.1.0'; | |
$v2 = '0.1.0a'; | |
echo ver_compare($v1, $v2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment