Open In App
Related Articles

PHP | Ds\Sequence rotate() Function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
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 abstract public Ds\Sequence::rotate ( int $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:
<?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); 
  
?> 

                    
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:
<?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); 
  
?> 

                    
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

Last Updated : 22 Aug, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads