PHP | ArrayIterator natsort() Function
The ArrayIterator::natsort() function is an inbuilt function in PHP which is used to sort an array naturally.
Syntax:
void ArrayIterator::natsort( void )
Parameters: This function does not accept any parameters.
Return Value: This function does not return any value.
Below programs illustrate the ArrayIterator::natsort() function in PHP:
Program 1:
<?php
$arrItr = new ArrayIterator(
array (
5 => 'G' ,
4 => 'e' ,
3 => 'E' ,
2 => 'k' ,
1 => 'S' ,
)
);
$arrItr ->natsort();
while ( $arrItr ->valid()) {
echo $arrItr ->current() . " " ;
$arrItr ->next();
}
?>
|
Program 2:
<?php
$arrItr = new ArrayIterator(
array ( "geeks" , "GEEKS" , "Geeks" , "gEEKS" )
);
$arrItr ->natsort();
var_dump( $arrItr );
?>
|
Output:
object(ArrayIterator)#1 (1) {
["storage":"ArrayIterator":private]=>
array(4) {
[1]=>
string(5) "GEEKS"
[2]=>
string(5) "Geeks"
[3]=>
string(5) "gEEKS"
[0]=>
string(5) "geeks"
}
}
Reference: https://www.php.net/manual/en/arrayiterator.natsort.php
Last Updated :
21 Nov, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...