Monday, June 8, 2026
HomeLanguagesPHP | DsSequence rotate() Function

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 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

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
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6895 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7018 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS