The PHP Function Version Compare
The php function version_compare() compares two PHP-standardized version numbers. It first replaces _, - and + with a dot. in the versionsangaben and inserts a dot. before and after every non number string so that for example '4.3.2RC1' becomes '4.3.2.RC.1.'. Then it compares the parts of the version strings starting from left to right. If a part contains special version strings like 'alpha' and 'beta' these are handled specially as shown below:
Time Complexity: O(n)
It is possible to pass the version_compare() function a third optional argument to select for a certain relationship between the two version numbers. Possible operators are
In addition, you can pass it a fourth optional argument to specify which of the two version numbers is to be used for comparison. This parameter is particularly useful in situations when you are developing with an unstable PHP release and need to know which of the two versions to compare the code against. The other alternative is to use a different method to find the differences in the versions of the library, such as the get_loaded_extensions() function, which will return an array with all enabled extensions and their names. This array can be used to identify the version of the library that is being used by your web application. This approach is also very handy if you are working with libraries that use versioned jar files to contain the code.