Compare two version strings in PHP

后端 未结 5 896
遇见更好的自我
遇见更好的自我 2020-12-10 11:28

How to compare two strings in version format? such that:

version_compare(\"2.5.1\",  \"2.5.2\") => -1 (smaller)
version_compare(\"2.5.2\",  \"2.5.2\") =&         


        
5条回答
  •  忘掉有多难
    2020-12-10 11:55

    Also, you can use the PHP built-in function as below by passing an extra argument to the version_compare()

    if(version_compare('2.5.2', '2.5.1', '>')) {
     print "First arg is greater than second arg";
    }
    

    Please see version_compare for further queries.

提交回复
热议问题