PHP नेटकेसॉर्ट () फ़ंक्शन
उदाहरण
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
)
परिभाषा और उपयोग
नैटकेसॉर्ट () फ़ंक्शन "प्राकृतिक क्रम" एल्गोरिथम का उपयोग करके एक सरणी को सॉर्ट करता है। मान अपनी मूल कुंजी रखते हैं।
एक प्राकृतिक एल्गोरिथम में, संख्या 2 संख्या 10 से कम है। कंप्यूटर सॉर्टिंग में, 10 2 से कम है, क्योंकि "10" में पहली संख्या 2 से कम है।
यह फ़ंक्शन केस-असंवेदनशील है।
वाक्य - विन्यास
natcasesort(array)
पैरामीटर मान
Parameter | Description |
---|---|
array | Required. Specifies the array to sort |
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: | सफलता पर सच। विफलता पर FALSE |
---|---|
पीएचपी संस्करण: | 4+ |
पीएचपी ऐरे संदर्भ