Friday, October 17, 2025
HomeLanguagesPHP | DsSequence reversed() Function

PHP | Ds\Sequence reversed() Function

The Ds\Sequence::reversed() function is an inbuilt function in PHP which is used to return the reverse copy of sequence element.

Syntax:

Ds\Sequence abstract public Ds\Sequence::reversed ( void )

Parameters: This function does not accepts any parameter.

Return Value: This function returns the reversed copy of sequence elements.

Below programs illustrate the Ds\Sequence::reversed() function in PHP:

Program 1:




<?php 
  
// Create new Sequence 
$seq = new \Ds\Vector([1, 2, 3, 4, 5]); 
  
// Display the sequence elements 
print_r($seq); 
  
echo("After reversing the sequence elements\n"); 
  
// Use reversed() function to reverse 
// the copy of sequence and display it 
print_r($seq->reversed()); 
  
?> 


Output:

Ds\Vector Object
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
)
After reversing the sequence elements
Ds\Vector Object
(
    [0] => 5
    [1] => 4
    [2] => 3
    [3] => 2
    [4] => 1
)

Program 2:




<?php 
  
// Create new Vector 
$seq = new \Ds\Vector(["Geeks", "for", "Geeks",
        "Computer", "Science", "Portal"]); 
  
// Display the elements 
print_r($seq); 
  
echo("Sequence after reversing\n"); 
  
// Use reversed() function to reverse 
// the element and display it 
print_r($seq->reversed());
  
?>


Output:

Ds\Vector Object
(
    [0] => Geeks
    [1] => for
    [2] => Geeks
    [3] => Computer
    [4] => Science
    [5] => Portal
)
Sequence after reversing
Ds\Vector Object
(
    [0] => Portal
    [1] => Science
    [2] => Computer
    [3] => Geeks
    [4] => for
    [5] => Geeks
)

Reference: https://www.php.net/manual/en/ds-sequence.reversed.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS