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, zambiatek 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!
 
				 
					


