PHP Ds\Set reverse() Function

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); ?> |
Output:
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); ?> |
Output:
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



