How to sort versioning info

前端 未结 3 1375
误落风尘
误落风尘 2020-12-30 01:39

What\'s the right way, to handle versioning indicators like 2.4 or 2.4.0.9 etc. to get the ability of sorting versions.

PHP says, that

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-30 02:03

    Storing it as a string allows you to make use of the version_compare() function:

    $versions = array('2.4','2.3.4','2.4.0.9');
    usort($versions, 'version_compare');
    

提交回复
热议问题