PHP의 natsort () 함수
예
배열을 정렬 :
<?php
$temp_files = array("temp15.txt","temp10.txt",
"temp1.txt","temp22.txt","temp2.txt");
sort($temp_files);
echo "Standard sorting: ";
print_r($temp_files);
echo "<br>";
natsort($temp_files);
echo "Natural order: ";
print_r($temp_files);
?>
$temp_files = array("temp15.txt","temp10.txt",
"temp1.txt","temp22.txt","temp2.txt");
sort($temp_files);
echo "Standard sorting: ";
print_r($temp_files);
echo "<br>";
natsort($temp_files);
echo "Natural order: ";
print_r($temp_files);
?>
»인스턴스를 실행
정의 및 사용
natsort () 함수는 배열을 정렬 "natural order"알고리즘을 사용합니다. 키가 원래 키를 유지합니다.
자연 정렬 알고리즘 수가 수가 10보다 작다. 은 "10"제 수가 2 개 미만이므로 컴퓨터 정렬 알고리즘에서, (10)은 2 미만이다.
문법
natsort( array )
参数 | 描述 |
---|---|
array | 必需。规定要进行排序的数组。 |
기술 세부 사항
반환 값 : | 이 TRUE를 반환 성공하면, 실패 할 경우 FALSE를 반환합니다. |
---|---|
PHP 버전 : | 4+ |
업데이트 로그 : | PHP 5.2.10 이후 이후, 제로 숫자 문자열 (예 : '00006') 가득 0을 무시됩니다. |
전체 PHP 배열 참조