PHP natcasesort() Function
Complete PHP Array Reference
Definition and Usage
The natcasesort() function sorts an array by using a "natural order" algorithm. The values
keep their original keys.
In a natural algorithm, the number 2 is less than the number 10. In computer
sorting, 10 is less than 2, because the first number in "10" is less than 2.
This function is case-insensitive.
This function returns TRUE on success, or FALSE on
failure.
Syntax
Parameter |
Description |
array |
Required. Specifies the array to sort |
Example
<?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);
?>
|
The output of the code above will be:
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
)
|
Complete PHP Array Reference
Whether you're new to XML or already an advanced user, the user-friendly views
and powerful entry helpers, wizards, and debuggers in XMLSpy are designed to
meet your XML and Web services development needs from start to finish.
- XML editor
- Graphical XML Schema / DTD editors
- XSLT 1.0/2.0 editor, debugger, profiler
- XQuery editor, debugger, profiler
- Support for Office Open XML (OOXML)
- Graphical WSDL editor & SOAP debugger
- Java, C#, C++ code generation
- And much more!
Download a fully functional free 30-day trial today!
|