Friday, October 17, 2025
HomeLanguagesPHP | DsDeque rotate() Function

PHP | Ds\Deque rotate() Function

The Ds\Deque::rotate() function is an inbuilt function in PHP which is used to rotate the elements of Deque by the given number of rotations.

Syntax:

public Ds\Deque::rotate( $rotations ) : void

Parameters: This function accepts single parameter $rotations which holds the number of rotation of the elements in Deque is to be rotated.

Return value: This function does not return any value.

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

Program 1:




<?php
  
// Declare a deque
$deck = new \Ds\Deque([1, 2, 3, 4, 5, 6]);
  
echo("Elements of Deque\n");
  
// Display the Deque elements
print_r($deck);
  
// Rotating the deque by 2 positions
$deck->rotate(2);
   
echo("Rotated Deque\n");
  
// Display the Deque elements
print_r($deck);
  
?>


Output:

Elements of Deque
Ds\Deque Object
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
)
Rotated Deque
Ds\Deque Object
(
    [0] => 3
    [1] => 4
    [2] => 5
    [3] => 6
    [4] => 1
    [5] => 2
)

Program 2:




<?php
  
// Declare a deque
$deck = new \Ds\Deque(["neveropen", "for", "neveropen", "practice"]);
  
echo("Elements of Deque\n");
  
// Display the Deque elements
print_r($deck);
  
// Rotating the deque by 2 positions
$deck->rotate(2);
   
echo("Rotated Deque\n");
  
// Display the Deque elements
print_r($deck);
  
?>


Output:

Elements of Deque
Ds\Deque Object
(
    [0] => neveropen
    [1] => for
    [2] => neveropen
    [3] => practice
)
Rotated Deque
Ds\Deque Object
(
    [0] => neveropen
    [1] => practice
    [2] => neveropen
    [3] => for
)

Reference: http://php.net/manual/en/ds-deque.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
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS