version_compare
Comparison of two versions of "PHP normalized" numeric strings
Function name: version_compare()
Applicable version: PHP 4.1.0 and above
Usage: The version_compare() function is used to compare two version numbers.
Syntax: int version_compare ( string $version1 , string $version2 [, string $operator ] )
parameter:
Return value: If version1 is less than version2, return -1; if version1 is greater than version2, return 1; if both are equal, return 0.
Example:
$version1 = "7.2.0"; $version2 = "7.3.0"; echo version_compare($version1, $version2); // 输出-1,因为7.2.0 小于7.3.0 echo version_compare($version1, $version2, "<"); // 输出true,因为7.2.0 小于7.3.0 echo version_compare($version1, $version2, ">="); // 输出false,因为7.2.0 不大于等于7.3.0 echo version_compare($version1, $version2, "=="); // 输出false,因为7.2.0 不等于7.3.0
The above example demonstrates the basic usage of the version_compare() function. You can pass different comparison operators according to your needs to compare version numbers and make corresponding logical judgments based on the return value.