English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP String Character String Functions Manual
The strnatcmp() function compares strings using a natural sorting algorithm (case-sensitive).
int strnatcmp ( string $str1 , string $str2 )
It compares two strings using a natural order algorithm, case-sensitive.
Similar to other string comparison functions, if str1 Less than str2 Return < 0; if str1 Greater than str2 Return > 0; if they are equal, return 0.
Number | Parameters and Description |
---|---|
1 | string1 The first string |
2 | string2 The second string |
Try the following example to compare the size of two strings:
<?php //Case-sensitive comparison of two strings echo strnatcmp("5w3codebox!","5w3codebox!); echo "<br>"; //Case-sensitive comparison of two strings echo strnatcmp("5w3codebox!","5w3codebox!); echo "<br>"; //The second string is greater than the first string echo strnatcmp("5w3codebox!","58w3codebox!); echo "<br>"; //The second string is less than the first string echo strnatcmp("101111w3codebox!","211w3codebox!); ?>Test and see‹/›
Output Result
0 1 -1 1