PHP | Ds\Sequence unshift() Function
Last Updated :
22 Aug, 2019
Improve
The Ds\Sequence::unshift() function is an inbuilt function in PHP which is used to add values to the font of the sequence.
Syntax:
php
Output:
php
Output:
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);
?>
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);
?>
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