English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
strnatcmp() function compares strings using natural sorting algorithm (case-sensitive).
int strnatcmp ( string $str1 , string $str2 )
It compares two strings using the natural order algorithm, case-sensitive.
Other string comparison functions, if str1 less than str2 return < 0; if str1 greater than str2 return > 0; 두자리가 같다면, return 0.
순번 | 인수와 설명 |
---|---|
1 | string1 첫 번째 문자열 |
2 | string2 두 번째 문자열 |
다음 예제를 시도하여 두 문자열의 크기를 비교해 보세요:
<?php //대소문자 구분 없이 두 문자열을 비교합니다 echo strnatcmp("5w3codebox!","5w3codebox!"); echo "<br>"; //대소문자 구분 없이 두 문자열을 비교합니다 echo strnatcmp("5w3codebox!","5w3codebox!"); echo "<br>"; //두 번째 문자열이 첫 번째 문자열보다 큽니다 echo strnatcmp("5w3codebox!","58w3codebox!"); echo "<br>"; //두 번째 문자열이 첫 번째 문자열보다 작습니다 echo strnatcmp("101111w3codebox!","211w3codebox!"); ?>테스트 보세요‹/›
출력 결과
0 1 -1 1