PHP | Ds\Sequence unshift() Function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
  
?>

chevron_right


Output:

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

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
  
?>

chevron_right


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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.