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 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
$seq = new \Ds\Vector();
$seq ->insert(0, "g" );
$seq ->insert(1, "e" );
$seq ->insert(2, "e" );
$seq ->insert(3, "k" );
$seq ->insert(4, "s" );
$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
$seq = new \Ds\Vector();
$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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
21 Aug, 2019
Like Article
Save Article