PHP natsort() Function
In this chapter you will learn:
- Definition for PHP natsort() Function
- Syntax for PHP natsort() Function
- Parameter for PHP natsort() Function
- Note for PHP natsort() Function
- Return value for PHP natsort() Function
- Example - sorts an array by using a "natural order" algorithm
Definition
The natsort() function sorts an array by using a "natural order" algorithm.
Syntax
PHP natsort() Function has the following syntax.
natsort(array)
Parameter
Parameter | Is Required | Description |
---|---|---|
array | Required. | Specifies the array to sort |
Note
This function is case-sensitive.
Return
This function returns TRUE on success, or FALSE on failure.
Example 1
Sort an array:
<?php/* j av a 2 s . c o m*/
$temp_files = array("a15","A10","A1","A22","A2");
sort($temp_files);
echo "Standard sorting: ";
print_r($temp_files);
echo "\n";
natsort($temp_files);
echo "Natural order: ";
print_r($temp_files);
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP next() Function
- Syntax for PHP next() Function
- PHP next() Function
- Note for PHP next() Functions
- Related methods
- Example - Holes in Arrays
- Example - Output the value of the current and the next element in the array
- Example - A demonstration of all related methods
Home » PHP Tutorial » PHP Array Functions