写一个版本比较函数并不是很困难的事情,但是PHP已经提供了一个-不亏是最好的语言……
version_compare 专门的版本比较函数。
使用举例:
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";
}