PHP Ds\Set reverse() Function
Last Updated :
16 Aug, 2019
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
$set = new \Ds\Set([ "10" , "20" , "30" ]);
echo "Initial Set: \n" ;
var_dump( $set );
$set ->reverse();
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
$set = new \Ds\Set([ "Geeks" , "for" , "Keegs" ]);
echo "Initial Set: \n" ;
var_dump( $set );
$set ->reverse();
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
Share your thoughts in the comments
Please Login to comment...