PHP.nl

version_compare

version_compare

Compares two "PHP-standardized" version number strings

 **version_compare** string $version1 string $version2  $operator
compares two "PHP-standardized"

version number strings. version_compare

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 compares the parts starting from left to right. If a part contains special version strings these are handled in the following order: < < = < = < =
< < = . 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. _``-``+``.``.``any string not found in this list``dev``alpha``a``beta``b``RC``rc``#``pl``p

version1First version number.

version2Second version number.

operator An optional operator. The possible operators are: , , , , , , , , , , , , , respectively. &lt;``lt``&lt;=``le``&gt;``gt``&gt;=``ge``==``=``eq``!=``&lt;&gt;``ne

This parameter is case-sensitive, values should be lowercase.

By default, returns if the first version is lower than the second, if they are equal, and if the second is lower. version_compare``-1``0``1

When using the optional argument, the function will return true if the relationship is the one specified by the operator, false otherwise. operator

The examples below use the constant, because it contains the value of the PHP version that is executing the code. PHP_VERSION

Voorbeeld: examples

<?php
if (version_compare(PHP_VERSION, '7.0.0') >= 0) {
    echo 'I am at least PHP version 7.0.0, my version: ' . PHP_VERSION . "\n";
}

if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
    echo 'I am at least PHP version 5.3.0, my version: ' . PHP_VERSION . "\n";
}

if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
    echo 'I am at least PHP version 5.0.0, my version: ' . PHP_VERSION . "\n";
}

if (version_compare(PHP_VERSION, '5.0.0', '<')) {
    echo 'I am still PHP 4, my version: ' . PHP_VERSION . "\n";
}
?>

Opmerking: > The constant holds current PHP version. PHP_VERSION

Opmerking: > Note that pre-release versions, such as 5.3.0-dev, are considered lower than their final release counterparts (like 5.3.0).

Opmerking: > Special version strings such as and are case sensitive. Version strings from arbitrary sources that do not adhere to the PHP standard may need to be lowercased via before calling . alpha``beta``strtolower``version_compare

phpversion``php_uname``function_exists