• PHP Video Tutorials

PHP - Ds Vector rotate() Function



Ds\Vector::rotate() function can rotate the verctor by a given number of rotations.

Syntax

public void Ds\Vector::rotate( int $rotations )

Ds\Vector::rotate() function can rotate the vector by a given number of rotations, that is equivalent to successively calling $vector->push($vector->shift()) if the number of rotations is positive, or $vector->unshift($vector->pop()) if negative.

Ds\Vector::rotate() function doesn't return any value. The vector of current instance can be rotated.

Example 1

<?php
   $vector = new \Ds\Vector([1, 2, 3, 4, 5]); 
   echo("The original vector: \n"); 
   print_r($vector); 
  
   $vector->rotate(2); 
   echo("\n The vector after rotating by 2 places: \n"); 
   print_r($vector); 
?>

Example-2

<?php 
   $vector = new \Ds\Vector([1, 2, 3, 4, 5]); 
   echo("The original vector: \n"); 
   print_r($vector); 
   
   $vector->rotate(4); 
   echo("\n The vector after rotating by 4 places: \n"); 
   print_r($vector); 
?>
php_function_reference.htm
Advertisements