PHP | Ds\Vector unshift() Function Last Updated : 22 Aug, 2019 Comments Improve Suggest changes Like Article Like Report The Ds\Vector::unshift() function is an inbuilt function in PHP which is used to adds elements to the front of vector. This function moves all the elements in the vector towards forward and adds the new element to the front. Syntax: void public Ds\Vector::unshift( $values ) Parameters: This function accepts single parameter $values which holds the values to be added to the vector. Return Value: This function does not return any value. Below programs illustrate the Ds\Vector::unshift() function in PHP: Program 1: PHP <?php // Create new Vector $vect = new \Ds\Vector([3, 6, 1, 2, 9, 7]); echo("Original vector:\n"); // Display the vector elements print_r($vect); echo("\nArray elements after inserting new element\n"); // Use unshift() function to aff elements $vect->unshift(10, 20, 30); // Display updated vector elements print_r($vect); ?> Output: Original vector: Ds\Vector Object ( [0] => 3 [1] => 6 [2] => 1 [3] => 2 [4] => 9 [5] => 7 ) Array elements after inserting a new element Ds\Vector Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 3 [4] => 6 [5] => 1 [6] => 2 [7] => 9 [8] => 7 ) Program 2: PHP <?php // Create new Vector $vect = new \Ds\Vector(["geeks", "for", "geeks"]); echo("Original vector:\n"); // Display the vector elements print_r($vect); echo("\nArray elements after inserting new element\n"); // Use unshift() function to aff elements $vect->unshift("PHP articles"); // Display updated vector elements print_r($vect); ?> Output: Original vector: Ds\Vector Object ( [0] => geeks [1] => for [2] => geeks ) Array elements after inserting a new element Ds\Vector Object ( [0] => PHP articles [1] => geeks [2] => for [3] => geeks ) Reference: http://php.net/manual/en/ds-vector.unshift.php Comment More infoAdvertise with us Next Article PHP | DsSequence unshift() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_vector Similar Reads PHP | DsDeque unshift() Function The Ds\Deque::unshift() function is an inbuilt function in PHP which is used to add the value in front of the deque. Syntax: void Ds\Deque::unshift( $values ) Parameters: This function accepts single parameter $values which holds the values to add in the front of the deque. Return Value: This functi 2 min read PHP | DsVector unshift() Function The Ds\Vector::unshift() function is an inbuilt function in PHP which is used to adds elements to the front of vector. This function moves all the elements in the vector towards forward and adds the new element to the front. Syntax: void public Ds\Vector::unshift( $values ) Parameters: This function 2 min read PHP | DsSequence 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 sequenc 1 min read PHP | DsDeque shift() Function The Ds\Deque::shift() function is an inbuilt function in PHP which is used to remove and return the first value of deque. Syntax: mixed Ds\Deque::shift( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the first value of deque which was removed. Be 1 min read PHP array_unshift() Function This inbuilt function of PHP is used to add one or more elements into an array and these elements are added to at the beginning of the array. All the elements that we add into the array are inserted in the same order, as they have been passed. They are numerically indexed starting from the 0th posit 3 min read PHP | DsVector shift() Function The Ds\Vector::shift() function is an inbuilt function in PHP which is used to remove the first element from the vector and return it. Syntax: mixed public Ds\Vector::shift( void ) Parameters: This function does not accept any parameter. Return Value: This function returns the value at index 0. Exce 1 min read PHP | DsMap sort() Function The Ds\Map::sort() function of DS\Map class in PHP is used to in-place sort the elements of a specified Map instance according to the values. By default, the Map is sorted according to the increasing order of the values. Syntax: Ds\Pair public Ds\Map::sort ( int $position ) Parameter: This function 2 min read PHP | DsSequence shift() Function The Ds\Sequence::shift() function is an inbuilt function in PHP which is used to removes the first element from the sequence and return it. Syntax: mixed abstract public Ds\Sequence::shift ( void ) Parameters: This function does not accepts any parameter. Return values: This function returns the fir 1 min read PHP array_shift() Function This inbuilt function of PHP removes the first element from an array and returns the value of the removed element. After the removal of the first element, the key of the remaining elements is modified and again re-numbered from the start, only if the keys are numerical. In other words, this function 2 min read PHP | DsDeque set() Function The Ds\Deque::set() function is an inbuilt function in PHP which is used to set the value at the given index in the Deque. Syntax: public Ds\Deque::set( $index, $value ) : void Parameters: This function accept two parameters as mentioned above and described below: index: This parameter holds the ind 2 min read Like