Reputation: 31
How can i compare two numbers in PHP which have four decimal places. version_compare does not seem to work with four decimal places. It will work for three.
Example: Is a > b Compare: a : 16.8.1.22.23 b : 16.8.1.23.40
Is there an easy way to do this ?
Upvotes: 1
Views: 342
Reputation: 6112
You can use the method
mixed version_compare ( string $version1 , string $version2 [, string $operator ] )
As third argument you set the comparison operator : <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne
For exemple :
if (version_compare('16.8.1.22.23', '16.8.1.23.40', '>')) {
// do something
}
In this exemple it won't enter the if because $version1
is lesser than $version2
.
ref : reference documentation for version_compare
Upvotes: 2