dqdfpmmi022763 2013-06-25 03:48
浏览 33

PHP版本号数学[重复]

This question already has an answer here:

I am working on a project where I can have different versions of the client and want to be able to do > and < math on the version numbers. The issue is the version numbers are something like 0.5.1.

The question is, is there anyway in PHP to do some sort of version number math where it is able to understand that type of numbering system?

</div>
  • 写回答

1条回答 默认 最新

  • dongqu9972 2013-06-25 03:58
    关注

    Use PHP's built-in function version_compare() for that.

    From the documentation page:

    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.

    Example:

    <?php
    if (version_compare(PHP_VERSION, '6.0.0') >= 0) {
        echo 'I am at least PHP version 6.0.0, my version: ' . PHP_VERSION . "
    ";
    }
    
    if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
        echo 'I am at least PHP version 5.3.0, my version: ' . PHP_VERSION . "
    ";
    }
    
    if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
        echo 'I am using PHP 5, my version: ' . PHP_VERSION . "
    ";
    }
    
    if (version_compare(PHP_VERSION, '5.0.0', '<')) {
        echo 'I am using PHP 4, my version: ' . PHP_VERSION . "
    ";
    }
    ?>
    

    (taken from the documentation page)

    I hope this helps. Good luck! :)

    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)