PHP | Ds\Deque insert() Function Last Updated : 14 Aug, 2019 Comments Improve Suggest changes Like Article Like Report 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 holds the index at which element is to be inserted. $value: This parameter holds the value to be inserted into the given index in Deque. Return Value: This function does not return any value. Exception: This function throws OutOfRangeException if the Deque is empty. Below programs illustrate the Ds\Deque::insert() function in PHP: Program 1: PHP <?php // Declare a deque $deck = new \Ds\Deque([1, 2, 3, 4, 5, 6]); echo("Elements in the Deque\n"); // Display the Deque elements print_r($deck); echo("\nInsert 10 at index 4 in the deque\n"); // Use insert() function to inserting // element in the deque at index 4 $deck->insert(4, 10); // Display the Deque elements print_r($deck); ?> Output: Elements in the Deque Ds\Deque Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) Insert 10 at index 4 in the deque Ds\Deque Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 10 [5] => 5 [6] => 6 ) Program 2: PHP <?php // Declare a deque $deck = new \Ds\Deque([1, 2, 3, 4, 5, 6]); echo("Original Deque\n"); // Display the Deque elements print_r($deck); echo("\nModified Deque\n"); // Use insert() function to inserting // element in the deque at index 4 $deck->insert(3, ...[10, 20, 30, 40]); // Display the Deque elements print_r($deck); ?> Output: Original Deque Ds\Deque Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) Modified Deque Ds\Deque Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 10 [4] => 20 [5] => 30 [6] => 40 [7] => 4 [8] => 5 [9] => 6 ) Reference: http://php.net/manual/en/ds-deque.insert.php Comment More infoAdvertise with us Next Article PHP | DsSequence insert() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-function 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 | 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 | DsDeque isEmpty() Function The Ds\Deque::isEmpty() function is an inbuilt function in PHP which is used to check the Deque is empty or not. Syntax: public Ds\Deque::isEmpty( void ) : bool Parameters: This function does not accept any parameter. Return Value: This function returns true if the Deque is empty, else return false. 1 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 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 | DsDeque last() Function The Ds\Deque::last() function is an inbuilt function in PHP which is used to return the last element of Deque if Deque is not empty. Syntax: public Ds\Deque::last( void ) : mixed Parameters: This function does not accept any parameter. Return Value: This function returns the last element in the dequ 2 min read Like