PHP Ds / sequence inverse () function

PHP

Syntax:
DsSequence abstract public DsSequence::reversed (void)
Parameters: this function takes no parameters.Returned value:this function returns the reverse sequence of sequence elements.The following programs illustrate the Ds / function Sequence::reversed()in PHP:Program 1: < ? php  
// Create a new sequence $seq = new DsVector ([1, 2, 3, 4, 5]);  
// Show sequence items print_r ( $seq ); echo ( " After reversing the sequence elements " );  
// Use the reversed() function to reverse
// copy the sequence and display it print_r ( $seq -> reversed());  
?>
Exit:
DsVector Object ( [0] = > 1 [1] = > 2 [2] = > 3 [3] = > 4 [4] = > 5) After reversing the sequence elements DsVector Object ([0] = > 5 [1] = > 4 [2] = > 3 [3] = > 2 [4] = > 1)
Program 2:  
// Create a new vector $seq = new DsVector ([ "Geeks" , "for" , "Geeks" , "Computer" , "Science" , "Portal" ]);  
// Show items print_r ( $seq ); echo ( " Sequence after reversing " );  
// Use the reversed() function to reverse
// element and display it print_r ( $seq -> reversed());  
?>
Exit:
DsVector Object ( [0] = > Geeks [1] = > for [2] = > Geeks [3] = > Computer [4] = > Science [5] = > Portal) Sequence after reversing DsVector Object ([ 0] = > Portal [1] = > Science [2] = > Computer [3] = > Geeks [4] = > for [5] = > Geeks)
Link: https://www.php.net/manual/en/ds- sequence.reversed.php



Get Solution for free from DataCamp guru