The Ds\Set::reverse() function of Ds\Set class in PHP is an inbuilt function which is used to reverse the order of elements present in the Set instance. This function reverses the Set in-place. That is, it does not uses any extra space and updates the original Set instance with reversed values.
Syntax:
void public Ds\Set::reverse ( void )
Parameters: This function does not accepts any parameters.
Return Value: This function does not returns any value. It reverses the order of elements in the actual Set instance.
Below programs illustrate the Ds\Set::reverse() function:
Program 1:
<?php // Declare new Set $set = new \Ds\Set(["10", "20", "30"]); // Display the initial Set element echo "Initial Set: \n"; var_dump($set); // Reverse the set $set->reverse(); // Print the reversed Set echo "\nReversed Set is: \n"; var_dump($set); ?> |
Initial Set:
object(Ds\Set)#1 (3) {
[0]=>
string(2) "10"
[1]=>
string(2) "20"
[2]=>
string(2) "30"
}
Reversed Set is:
object(Ds\Set)#1 (3) {
[0]=>
string(2) "30"
[1]=>
string(2) "20"
[2]=>
string(2) "10"
}
Program 2:
<?php // Declare new Set $set = new \Ds\Set(["Geeks", "for", "Keegs"]); // Display the initial Set element echo "Initial Set: \n"; var_dump($set); // Reverse the set $set->reverse(); // Print the reversed Set echo "\nReversed Set is: \n"; var_dump($set); ?> |
Initial Set:
object(Ds\Set)#1 (3) {
[0]=>
string(5) "Geeks"
[1]=>
string(3) "for"
[2]=>
string(5) "Keegs"
}
Reversed Set is:
object(Ds\Set)#1 (3) {
[0]=>
string(5) "Keegs"
[1]=>
string(3) "for"
[2]=>
string(5) "Geeks"
}
Reference: http://php.net/manual/en/ds-set.reverse.php
Recommended Posts:
- PHP | Ds\Map reverse() Function
- PHP | Ds\Deque reverse() Function
- PHP | Ds\Vector reverse() Function
- PHP | Ds\Sequence reverse() Function
- PHP | Reverse a String
- How to get the function name inside a function in PHP ?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | imagecreatetruecolor() Function
- PHP | fpassthru( ) Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- PHP | Imagick floodFillPaintImage() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


