Home > PHP > Function > PHP Options/Info > version_compare()

version_compare()

version_compare - Compares two "PHP-standardized" version number strings

Syntax

mixed version_compare (string $version1, string $version2, string $operator)

Arguments

  • version1 - First version number.
  • version2 - Second version number.
  • operator - If you specify the third optional operator argument, you can test for a particular relationship. The possible operators are: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, nerespectively. This parameter is case-sensitive, so values should be lowercase.

Description

version_compare() compares two "PHP-standardized" version number strings. This is useful if you would like to write programs working only on some versions of PHP.

Version

PHP 4.1.0, 5

Return value

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