PHP natcasesort function ()
Definicja i Wykorzystanie
Funkcja natcasesort () korzysta z "naturalnego porządku" algorytm sortowania tablicy. Klawisze zachowują swoje oryginalne kluczyki.
Algorytm sortowania naturalne, liczba jest mniejsza od liczby 10. W algorytmach komputerowych sortowania, 10 jest mniejsza niż 2, ponieważ "10" pierwsza liczba jest mniejsza niż 2.
Funkcja ta nie jest uwzględniana wielkość liter.
Jeśli się powiedzie, funkcja zwraca TRUE, w przypadku niepowodzenia zwraca FALSE.
gramatyka
natcasesort(array)
参数 | 描述 |
---|---|
array | 必需。规定要进行排序的数组。 |
Przykłady
<?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);
?>
$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);
?>
Powyższy kod będzie wyjściowe:
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
)
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
)
Kompletna PHP Array Reference