Reputation: 17365
I have a version number as a string, the version number can have major version as well as up to 3 minor version positions.
E.g. 3.4.0.1
I need to find out if this version is within a predefined version range:
E.g 3.1.0 - 3.3.5.1
I can parse the versions to 4 integers and do a comparison then but I'm sure there is a much more elegant solution for that.
Thanks
I guess it can be simplified further if assuming that the version range has only one minor version position, E.g 3.0 - 3.4
Upvotes: 2
Views: 216
Reputation: 19231
Use version_compare:
$version = "3.4.0.1";
if (version_compare($version, "3.1.0", ">=") && version_compare($version, "3.3.5.1", "<=")) {
//Version in range
}
Upvotes: 5