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:
<?php // Create new sequence $seq = new \Ds\Vector([12, 15, 18, 20]); // Use unshift() function to // the sequence element $seq ->unshift( "Beginner" ); $seq ->unshift( "1" , 1); print_r( $seq ); ?> |
Output:
Ds\Vector Object ( [0] => 1 [1] => 1 [2] => Beginner [3] => 12 [4] => 15 [5] => 18 [6] => 20 )
Program 2:
<?php // Create new sequence $seq = new \Ds\Vector([ "Beginner" , "for" , "Beginner" ]); // 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) "Beginner" [4]=> string(3) "for" [5]=> string(5) "Beginner" }
Reference: http://php.net/manual/en/ds-sequence.unshift.php