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 |
รายละเอียดทางเทคนิค
คืนมูลค่า: | จริงกับความสำเร็จ FALSE เมื่อล้มเหลว |
---|---|
รุ่น PHP: | 4+ |
❮ การอ้างอิงอาร์เรย์ PHP