PHP natcasesort() 함수
예시
natsort() 및 natcasesort()를 사용하여 배열을 정렬합니다.
<?php
$temp_files = array("temp15.txt","Temp10.txt",
"temp1.txt","Temp22.txt","temp2.txt");
natsort($temp_files);
echo "Natural order: ";
print_r($temp_files);
echo "<br />";
natcasesort($temp_files);
echo "Natural order case insensitve: ";
print_r($temp_files);
?>
위 코드의 출력은 다음과 같습니다.
Natural order:
Array
(
[0] => Temp10.txt
[1] => Temp22.txt
[2] => temp1.txt
[4] => temp2.txt
[3] => temp15.txt
)
Natural order case insensitve:
Array
(
[2] => temp1.txt
[4] => temp2.txt
[0] => Temp10.txt
[3] => temp15.txt
[1] => Temp22.txt
)
정의 및 사용
natcasesort() 함수는 "자연 순서" 알고리즘을 사용하여 배열을 정렬합니다. 값은 원래 키를 유지합니다.
자연 알고리즘에서 숫자 2는 숫자 10보다 작습니다. 컴퓨터 정렬에서 "10"의 첫 번째 숫자는 2보다 작기 때문에 10은 2보다 작습니다.
이 함수는 대소문자를 구분하지 않습니다.
통사론
natcasesort(array)
매개변수 값
Parameter | Description |
---|---|
array | Required. Specifies the array to sort |
기술적 세부 사항
반환 값: | 성공 시 TRUE입니다. 실패시 FALSE |
---|---|
PHP 버전: | 4+ |
❮ PHP 배열 참조