version_compare()
Use this function to compare two PHP version numbers. By default it will return zero if they are the same, -1 if the first is a lower version, or 1 if the second is the lower version.
You may also give it a comparison operator as a third parameter and it will return either true or false for that comparison. Valid comparison operators are: <, >, ==, =<, >=, != or their equivalents: lt, gt, eq, le, ge, ne, <>
This function also works with versions other than full release versions such as beta, release candidates, etc.
In these examples, we’re using PHP_VERSION which is “5.3.0″ here.
$a = '6.0'; $b = '5.3.0'; $c = '5.2.9'; $x = version_compare( PHP_VERSION, $a ); // -1 $x = version_compare( PHP_VERSION, $b ); // 0 $x = version_compare( PHP_VERSION, $c ); // 1 $x = version_compare( PHP_VERSION, $b, '==' ); // true $x = version_compare( PHP_VERSION, 5.3, '==' ); // false $x = version_compare( PHP_VERSION, $b, '<' ); // false $x = version_compare( PHP_VERSION, $b, '>' ); // false
See the manual entry for version_compare()
