• PHP Video Tutorials

PHP - Ds Vector unshift() Function



Ds\Vector::unshift() function can add values to the front of a vector.

Syntax

public void Ds\Vector::unshift([ mixed $values ] )

Ds\Vector::unshift() function can add values to the front of a vector, moving all current values forward to make room for new values.

Ds\Vector::unshift() function doesn't return any value.

Example 1

<?php 
   $vector = new \Ds\Vector([2, 5, 8, 4, 7, 1]); 
   echo("The original vector: \n"); 
   print_r($vector); 
   echo("\n The array elements after inserting new element: \n"); 
   
   $vector->unshift(10, 20, 30); 
   print_r($vector);
?>

Example 2

<?php 
   $vector = new \Ds\Vector(["Tutorials", "Point", "Tutorix"]); 
  
   echo("The original vector: \n"); 
   print_r($vector); 
  
   echo("\n The array elements after inserting new element: \n");
   $vector->unshift("India"); 
  
   print_r($vector); 
?>
php_function_reference.htm
Advertisements