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 SplHeap insert() Function The SplHeap::insert() function is an inbuilt function in PHP which is used to insert an element in the heap by sifting it up. Generally, the Heap Data Structure are of two types: Max-Heap: In a Max-Heap the key present at the root node must be greatest among the keys present at all of its children. 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 PHP | DsVector set() Function The Ds\Vector::set() function is an inbuilt function in PHP which is used to set the value in the vector at the given index. Syntax: void public Ds\Vector::set( $index, $value ) Parameters: This function accepts two parameters as mentioned above and described below: $index: This parameter holds the 2 min read PHP | DsVector get() Function The Ds\Vector::get() function is an inbuilt function in PHP which is used to return the element at the given index. Syntax: mixed public Ds\Vector::get( $index ) Parameters: This function accepts a single parameter $index which contains the index (0-based indexing) at which the element is to be retu 1 min read PHP | DsMap values() Function The Ds\Map::values() function is an inbuilt function in PHP which is used to return a sequence of the map's values. Syntax: Ds\Sequence public Ds\Map::values ( void ) Parameters: This function does not accepts any parameters. Return Value: It returns a Ds\Sequence containing all the values of the ma 1 min read Like