Description
int
version_compare ( string version1, string version2 [, string operator])
version_compare() compares two
"PHP_standardized" version number strings_ This is useful if you
would like to write programs working only on some versions of
PHP_
version_compare() returns _1 if the first
version is lower than the second, 0 if they are equal, and +1 if
the second is lower_
The function first replaces _, _
and + with a dot _ in the version
strings and also inserts dots _ before and after any
non number so that for example '4_3_2RC1' becomes '4_3_2_RC_1'_ Then it
splits the results like if you were using explode('_',$ver)_ Then it
compares the parts starting from left to right_ If a part contains
special version strings these are handled in the following order:
dev < alpha =
a < beta =
b < RC <
pl_ This way not only versions with different levels
like '4_1' and '4_1_2' can be compared but also any PHP specific version
containing development state_
If you specify the third optional operator
argument, you can test for a particular relationship_ The
possible operators are: <,
lt, <=,
le, >,
gt, >=,
ge, ==,
=, eq,
!=, <>,
ne respectively_ Using this argument, the
function will return 1 if the relationship is the one specified
by the operator, 0 otherwise_
Ejemplo 1_ version_compare() example <?php
// prints _1
echo version_compare("4_0_4", "4_0_6");
// these all print 1
echo version_compare("4_0_4", "4_0_6", "<");
echo version_compare("4_0_6", "4_0_6", "eq");
?> |
|