Open In App

PHP | Ds\Sequence unshift() Function

Last Updated : 22 Aug, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The Ds\Sequence::unshift() function is an inbuilt function in PHP which is used to add values to the font of the sequence.

Syntax:

void abstract public Ds\Sequence::unshift( $values )

Parameters: This function accepts a single parameter $values which contains values to add in the font of the sequence.

Return value: This function does not return any values.

Below programs illustrate the Ds\Sequence::unshift() function in PHP:

Program 1:




<?php
   
// Create new sequence
$seq new \Ds\Vector([12, 15, 18, 20]);
  
// Use unshift() function to 
// the sequence element
$seq->unshift("Geeks");
  
$seq->unshift("1", 1);
  
print_r($seq);
  
?>


Output:

Ds\Vector Object
(
    [0] => 1
    [1] => 1
    [2] => Geeks
    [3] => 12
    [4] => 15
    [5] => 18
    [6] => 20
)

Program 2:




<?php
   
// Create new sequence
$seq new \Ds\Vector(["Geeks", "for", "Geeks"]);
  
// Use unshift() function to 
// the sequence element
$seq->unshift(1);
  
$seq->unshift("G", 10);
  
var_dump($seq);
  
?>


Output:

object(Ds\Vector)#1 (6) {
  [0]=>
  string(1) "G"
  [1]=>
  int(10)
  [2]=>
  int(1)
  [3]=>
  string(5) "Geeks"
  [4]=>
  string(3) "for"
  [5]=>
  string(5) "Geeks"
}

Reference: http://php.net/manual/en/ds-sequence.unshift.php


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads