version_compare
Function • Params and return types changed in PHP 8.0
Compares two "PHP-standardized" version number strings.
version_compare Function synopsis
version_compare(
string $version1,
string $version2,
?string $operator = null
): int|bool
Parameters
$version1
Typestring
First version number.
$version2
Typestring
Second version number.
$operator
OptionalType?stringDefault valuenull
An optional operator. The possible operators
are: <, lt,
<=, le, >,
gt, >=, ge,
==, =, eq,
!=, <>, ne
respectively.
Return value
Typeint|bool
By default, 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.
When using the optional $operator argument, the
function will return true if the relationship is the one specified
by the operator, false otherwise.
Changes to the version_compare Function
PHP 8.0
- Return type added:
int|bool - Parameter name of parameter #1 changed:
$ver1to$version1 - Parameter type added for parameter #1 (
$version1):string - Parameter name of parameter #2 changed:
$ver2to$version2 - Parameter type added for parameter #2 (
$version2):string - Parameter name of parameter #3 changed:
$operto$operator - Parameter type added for parameter #3 (
$operator):?string - Parameter default value added for position #3 (
$operator):null
version_compare(
- $ver1,
+ string $version1,
- $ver2,
+ string $version2,
- $oper
+ ?string $operator = null
- )
+ ): int|bool version_compare Function Availability
version_compare Function Availability| PHP Version | Availability |
|---|---|
| PHP 8.6Upcoming Release | Yes |
| PHP 8.5Supported (Latest) | Yes |
| PHP 8.4Supported | Yes |
| PHP 8.3Security-Fixes Only | Yes |
| PHP 8.2Security-Fixes Only | Yes |
| PHP 8.1Unsupported | Yes |
| PHP 8.0Unsupported | Yes |
| PHP 7.4Unsupported | Yes |
| PHP 7.3Unsupported | Yes |
| PHP 7.2Unsupported | Yes |
| PHP 7.1Unsupported | Yes |
| PHP 7.0Unsupported | Yes |
| PHP 5.6Unsupported | Yes |
| PHP 5.5Unsupported | Yes |
| PHP 5.4Unsupported | Yes |
| PHP 5.3Unsupported | Yes |