PHP | Ds\Vector insert() Function Last Updated : 22 Aug, 2019 Comments Improve Suggest changes Like Article Like Report The Ds\Vector::insert() function is an inbuilt function in PHP which is used to insert the element into the vector at the given index. Syntax: void public Ds\Vector::insert( $index, $values ) Parameters: This function accepts two parameter as mentioned above and described below: $index: This parameter holds the index at which element is to be inserted. $value: This parameter holds the value which is to be inserted. Return Value: This function does not return any value. Exception: This function returns OutOfRangeException if the index is not valid. Below programs illustrate the Ds\Vector::insert() function in PHP: Program 1: PHP <?php // Declare new vector $vector = new \Ds\Vector([1, 2, 4, 5]); // Display the Vector element print_r($vector); // Use insert() function to add // element in the vector $vector->insert(2, 3); // Display the vector element print_r($vector); ?> Output: Ds\Vector Object ( [0] => 1 [1] => 2 [2] => 4 [3] => 5 ) Ds\Vector Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) Program 2: PHP <?php // Declare new vector $vector = new \Ds\Vector(["geeks", "for", "geeks"]); // Display the Vector element print_r($vector); // Use insert() function to add // element in the vector $vector->insert(1, "practice"); // Display the vector element print_r($vector); ?> Output: Ds\Vector Object ( [0] => geeks [1] => for [2] => geeks ) Ds\Vector Object ( [0] => geeks [1] => practice [2] => for [3] => geeks ) Reference: http://php.net/manual/en/ds-vector.insert.php Comment More infoAdvertise with us Next Article PHP | DsSequence insert() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_vector Similar Reads PHP | DsDeque insert() Function The Ds\Deque::insert() function is an inbuilt function in PHP which is used to insert the value at the given index in the Deque. Syntax: public Ds\Deque::insert( $index, $values ) : void Parameters: This function accepts two parameter as mentioned above and described below: $index: This parameter ho 2 min read PHP | DsVector insert() Function The Ds\Vector::insert() function is an inbuilt function in PHP which is used to insert the element into the vector at the given index. Syntax: void public Ds\Vector::insert( $index, $values ) Parameters: This function accepts two parameter as mentioned above and described below: $index: This paramet 2 min read PHP | DsSequence insert() Function The Ds\Sequence::insert() function is an inbuilt function in PHP which is used to insert value in the sequence at the given index. Syntax: void abstract public Ds\Sequence::insert ( int $index [, mixed $...values ] ) Parameter: This function accepts two parameter as mentioned above and described bel 2 min read PHP | DsVector isEmpty() Function The Ds\Vector::isEmpty() function is an inbuilt function in PHP which is used to check the vector is empty or not. Syntax: bool public Ds\Vector::isEmpty( void ) Parameters: This function does not accept any parameter. Return Value: This function returns true if the vector is empty, false otherwise. 1 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 PHP | DsDeque get() Function The Ds\Deque::get() function is an inbuilt function in PHP which is used to return the value at the given index. Syntax: public Ds\Deque::get( $index ) : mixed Parameters: This function accepts single parameter $index which holds the index for which element is to be found. Return Value: This functio 2 min read Like