Definition and Usage
定義和用法
The strnatcmp() function compares two strings using a "natural" algorithm.
strnatcmp()函數的作用是:用自然運算法則比較字符串(大小寫敏感)。
In a natural algorithm, the number 2 is less than the number 10. In computer sorting, 10 is less than 2, because the first number in "10" is less than 2.
在“自然運算法則”中,2比10小。在計算機序列當中,10比2小,因為“10”中的第一個數字是“1”,它小於2。
This function returns:
這個函數將返回下列值:
•0 - if the two strings are equal
0 – 如果字符串相等
•<0 - if string1 is less than string2
<0 – 如果string1小於string2
•>0 - if string1 is greater than string2
>0 – 如果string1大於string2
Syntax
語法
Tips and Notes
注意點
Note: The strnatcmp() is case-sensitive.
注意:strnatcmp()函數是區分大小寫的。
--------------------------------------------------------------------------------
Example
案例
復制代碼 代碼如下:
<?phpecho strnatcmp("2Hello world!","10Hello world!");echo "<br />";echo strnatcmp("10Hello world!","2Hello world!");?>
The output of the code above will be:
上述代碼將輸出下面的結果:-1 1