PHP | Ds\Sequence insert() Function
The Ds\Sequence::insert() function is an inbuilt function in PHP which is used to insert value in the sequence at given index.
Syntax:
abstract public Ds\Sequence::insert( $index, $values ) : void
Parameters: This function accepts two parameter as mentioned above and described below:
- $index: This parameter hold the index value where element inserted. Its value lies between 0 <= $index <= count. Where count indicate number of element in the sequence.
- $values: This parameter hold the value which to be inserted.
Return Value: This function does not return any values.
Below programs illustrate the Ds\Sequence::insert() function in PHP:
Program 1:
<?php // Create new sequence $seq = new \Ds\Vector(); // Use insert() function $seq->insert(0, "g"); // Use insert() function $seq->insert(1, "e"); // Use insert() function $seq->insert(2, "e"); // Use insert() function $seq->insert(3, "k"); // Use insert() function $seq->insert(4, "s"); // Use insert() function $seq->insert(5, 4); var_dump($seq); ?> |
Output:
object(Ds\Vector)#1 (6) {
[0] => string(1) "g"
[1] => string(1) "e"
[2] => string(1) "e"
[3] => string(1) "k"
[4] => string(1) "s"
[5] => int(4)
}
Program 2:
<?php // Create new sequence $seq = new \Ds\Vector(); // Use insert() function to insert // element in the sequence $seq->insert(0, 1, 2, 3, 4, 5, ["g", "e", "e", "k", 1, 2]); var_dump($seq); ?> |
Output:
object(Ds\Vector)#1 (6) {
[0] => int(1)
[1] => int(2)
[2] => int(3)
[3] => int(4)
[4] => int(5)
[5] => array(6) {
[0] => string(1) "g"
[1] => string(1) "e"
[2] => string(1) "e"
[3] => string(1) "k"
[4] => int(1)
[5] => int(2)
}
}
Reference: http://php.net/manual/en/ds-sequence.insert.php
Recommended Posts:
- PHP | Ds\Vector insert() Function
- PHP | Ds\Deque insert() Function
- Insert string at specified position in PHP
- How to insert line break before an element using CSS?
- How to insert new row at a certain index in a table in jQuery ?
- Program to Insert new item in array on any position in PHP
- Java Servlet and JDBC Example | Insert data in MySQL
- How to insert an item into array at specific index in JavaScript?
- How to get the function name from within that function using JavaScript ?
- p5.js | hex() function
- PHP Ds\Set get() Function
- p5.js | str() function
- PHP | exp() Function
- PHP Ds\Set sum() Function
- PHP | each() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



