PHP natcasesort () Funktion
Definition und Verwendung
natcasesort () Funktion verwendet einen "natürlichen Ordnung" Algorithmus, um die Anordnung zu sortieren. Schlüssel behalten ihre Originalschlüssel.
Natürliche Sortieralgorithmus ist die Zahl kleiner als die Zahl 10. In Computer Sortieralgorithmen, 10 weniger als 2, weil die "10", die erste Zahl kleiner als 2 ist.
Diese Funktion wird nicht zwischen Groß- und Kleinschreibung.
Wenn dies gelingt, gibt die Funktion TRUE, im Fehlerfall FALSE zurück.
Grammatik
natcasesort(array)
参数 | 描述 |
---|---|
array | 必需。规定要进行排序的数组。 |
Beispiele
<?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);
?>
Der obige Code gibt:
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
)
Komplette PHP - Array - Referenz