PHP natcasesort () function
Definisi dan Penggunaan
natcasesort () fungsi menggunakan "tatanan alam" algoritma untuk mengurutkan array. Kunci mempertahankan kunci asli mereka.
algoritma sorting alam, jumlah ini lebih kecil dari jumlah 10. Dalam algoritma komputer menyortir, 10 kurang dari 2, karena "10" nomor pertama adalah kurang dari 2.
Fungsi ini tidak case-sensitive.
Jika berhasil, fungsi mengembalikan TRUE, pada kegagalan kembali FALSE.
tatabahasa
natcasesort(array)
参数 | 描述 |
---|---|
array | 必需。规定要进行排序的数组。 |
contoh
<?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);
?>
Di atas Output kode kehendak:
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
)
Lengkap PHP Array Referensi