strnatcmp - 자연 순서 알고리즘을 사용한 문자열 비교
strnatcmp - 자연 순서 알고리즘을 사용한 문자열 비교
설명 ¶
int strnatcmp ( string $str1 , string $str2 )
이 함수는 인간과 같은 방식으로 영숫자 문자열을 정렬하는 비교 알고리즘을 구현합니다. 이것은 "자연 순서 부"라고합니다. 이 비교는 대소 문자를 구분합니다.
매개 변수 ¶
str1
첫 번째 문자열.
str2
두 번째 문자열.
반환 값 ¶
다른 문자열 비교 함수와 마찬가지로이 값 str1은보다 작 으면 <0을 반환합니다 str2. 0 str1보다 크면 str20, 같으면 0.
예 ¶
이 알고리즘과 일반 컴퓨터 문자열 정렬 알고리즘 ( strcmp () 에서 사용됨)의 차이점 은 다음과 같습니다.
<?php
$arr1 = $arr2 = array("img12.png", "img10.png", "img2.png", "img1.png");
echo "Standard string comparison\n";
usort($arr1, "strcmp");
print_r($arr1);
echo "\nNatural order string comparison\n";
usort($arr2, "strnatcmp");
print_r($arr2);
?>
위의 예제는 다음과 같이 출력됩니다 :
표준 문자열 비교
정렬
(
[0] => img1.png
[1] => img10.png
[2] => img12.png
[3] => img2.png
)
자연 순서 문자열 비교
정렬
(
[0] => img1.png
[1] => img2.png
[2] => img10.png
[3] => img12.png
)
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 5276 | 2년 전 | 1331 | |||
| 5275 | 2년 전 | 1401 | |||
| 5274 | 기타 | 2년 전 | 815 | ||
| 5273 | JavaScript |
swallow
|
2년 전 | 1045 | |
| 5272 | node.js |
swallow
|
2년 전 | 742 | |
| 5271 | JavaScript |
swallow
|
2년 전 | 1495 | |
| 5270 | PHP |
swallow
|
2년 전 | 844 | |
| 5269 | node.js |
swallow
|
2년 전 | 679 | |
| 5268 | node.js |
swallow
|
2년 전 | 1208 | |
| 5267 | PHP |
swallow
|
2년 전 | 1589 | |
| 5266 | MySQL |
swallow
|
2년 전 | 1088 | |
| 5265 | PHP |
swallow
|
2년 전 | 2029 | |
| 5264 | JavaScript |
swallow
|
2년 전 | 858 | |
| 5263 | 기타 |
swallow
|
2년 전 | 2980 | |
| 5262 | 기타 |
swallow
|
2년 전 | 667 | |
| 5261 | node.js |
swallow
|
2년 전 | 1059 | |
| 5260 | JavaScript |
swallow
|
2년 전 | 1508 | |
| 5259 | node.js |
swallow
|
2년 전 | 728 | |
| 5258 | node.js |
swallow
|
2년 전 | 1741 | |
| 5257 | node.js |
swallow
|
2년 전 | 1292 | |
| 5256 | PHP |
swallow
|
2년 전 | 1938 | |
| 5255 | node.js |
swallow
|
2년 전 | 684 | |
| 5254 | PHP |
swallow
|
2년 전 | 3011 | |
| 5253 | node.js |
swallow
|
2년 전 | 675 | |
| 5252 | 정규표현식 |
swallow
|
2년 전 | 621 | |
| 5251 | node.js |
swallow
|
2년 전 | 876 | |
| 5250 | PHP |
swallow
|
2년 전 | 1110 | |
| 5249 | node.js |
swallow
|
2년 전 | 1059 | |
| 5248 | PHP |
swallow
|
2년 전 | 1409 | |
| 5247 | node.js |
swallow
|
2년 전 | 1014 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기