PHP | ArrayIterator asort() Function
Last Updated :
27 Mar, 2023
The ArrayIterator::asort() function is an inbuilt function in PHP which is used to sort the array values.
Syntax:
void ArrayIterator::asort( void )
Parameters: This function does not accept any parameters.
Return Value: This function does not return any value.
Below programs illustrate the ArrayIterator::asort() function in PHP:
Program 1:
php
<?php
$arrItr = new ArrayIterator(
array ( 'G' , 'e' , 'e' , 'k' , 's' , 'f' , 'o' , 'r' )
);
$arrItr ->asort();
while ( $arrItr ->valid()) {
echo $arrItr ->current();
$arrItr ->next();
}
?>
|
Program 2:
php
<?php
$arrItr = new ArrayIterator(
array ("Geeks", " for ", "Geeks")
);
$arrItr ->asort();
foreach ( $arrItr as $key => $val ) {
echo $key . " => " . $val . "\n";
}
?>
|
Output:
0 => Geeks
2 => Geeks
1 => for
Reference: https://www.php.net/manual/en/arrayiterator.asort.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...