PHP Ds\Set reverse() Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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 <?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 <?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: https://www.php.net/manual/en/ds-set.reverse.php Create Quiz Comment G gopaldave Follow 0 Improve G gopaldave Follow 0 Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_set Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like