English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The strnatcasecmp() function uses the "natural order" algorithm to compare strings (case-insensitive).
strnatcasecmp(string1,string2)
It uses a natural algorithm to compare two strings. This function implements a comparison algorithm for sorting numeric strings in human habit.
In natural algorithms, numbers 5 Less than a number 10. In computer sorting,10 Less than 5This is because 10 The first number is less than 5.
Similar to other string comparison functions, if string1 Less than string2 Returns < 0; if string1 Greater than string2 Returns > 0; if they are equal, returns 0.
Number | Parameters and Description |
---|---|
1 | string1 The first string |
2 | string2 The second string |
Try the following example, strnatcasecmp uses a "natural" algorithm to compare two strings (case-insensitive):
<?php //Case-insensitive comparison of two strings echo strnatcasecmp("5w3codebox!"5w3codebox!'); echo "<br>"; //The second string is greater than the first string echo strnatcasecmp("5w3codebox!"58w3codebox!'); echo "<br>"; //The second string is less than the first string echo strnatcasecmp("101111w3codebox!"211w3codebox!'); ?>Test and see‹/›
Output Result
0 -1 1