PHP | Ds\Sequence rotate() Function

The Ds\Sequence::rotate() function is an inbuilt function in PHP which is used to rotate the sequence element by a given number of rotations.

Syntax:

void Ds\Sequence::rotate( $rotations )

Parameters: This function accepts single parameter $rotations which holds the number of rotations.



Return Value: This function does not return any value.

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

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
  
// Create new Sequence
$seq = new \Ds\Vector([1, 2, 3, 4, 5]); 
  
echo("Original Sequence\n"); 
  
// Display the Sequence elements 
print_r($seq); 
  
// Use rotate() function to rotate 
// the sequence elements 
$seq->rotate(3); 
  
echo("\nSequence after rotating by 3 places\n"); 
  
// Display the Sequence elements 
print_r($seq); 
  
?> 

chevron_right


Output:

Original Sequence
Ds\Vector Object
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
)

Sequence after rotating by 3 places
Ds\Vector Object
(
    [0] => 4
    [1] => 5
    [2] => 1
    [3] => 2
    [4] => 3
)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
  
// Create new Sequence
$seq = new \Ds\Vector(["Geeks", "for", "Geeks"
        "Computer", "Science", "Portal"]); 
  
echo("Original Sequence\n"); 
  
// Display the Sequence elements 
print_r($seq); 
  
// Use rotate() function to rotate 
// the sequence elements 
$seq->rotate(8); 
  
echo("\nSequence after rotating by 8 places\n"); 
  
// Display the Sequence elements 
print_r($seq); 
  
?> 

chevron_right


Output:

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

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

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.