The Ds\Sequence::push() function is an inbuilt function in PHP which adds values to the end of the sequence.
Syntax:
void abstract public Ds\Sequence::push( $values )
Parameters: This function accepts single parameter $values which contains one or more values. It hold the value to be added in the sequence.
Return value: This function does not return any value.
Below programs illustrate the Ds\Sequence::push() function in PHP:
Program 1:
<?php // Create new sequence $seq = new \Ds\Vector([12, 15, 18, 20]); // Use push() function to add // element in the sequence $seq->push(24); // Use push() function to add // element in the sequence $seq->push("S"); // Use push() function to add // element in the sequence $seq->push("Geeks"); // Use push() function to add // element in the sequence $seq->push(2); var_dump($seq); ?> |
Output:
object(Ds\Vector)#1 (8) {
[0]=>
int(12)
[1]=>
int(15)
[2]=>
int(18)
[3]=>
int(20)
[4]=>
int(24)
[5]=>
string(1) "S"
[6]=>
string(5) "Geeks"
[7]=>
int(2)
}
Program 2:
<?php // Create new sequence $seq = new \Ds\Vector([12, 15, 18, 20]); $arr = array ("g", "e", "e", "k"); // Loop run for every array element foreach ($arr as $val) { // Use push() function to add // element in the sequence $seq->push($val); } var_dump($seq); ?> |
Output:
object(Ds\Vector)#1 (8) {
[0]=>
int(12)
[1]=>
int(15)
[2]=>
int(18)
[3]=>
int(20)
[4]=>
string(1) "g"
[5]=>
string(1) "e"
[6]=>
string(1) "e"
[7]=>
string(1) "k"
}
Reference: http://php.net/manual/en/ds-sequence.push.php
Recommended Posts:
- PHP | Ds\Vector push() Function
- PHP | Ds\Deque push() Function
- PHP | Ds\Stack push() Function
- PHP Ds\PriorityQueue push() Function
- PHP Ds\Queue push() Function
- PHP | SplDoublyLinkedList push() Function
- How to push a value based on matched value in PHP ?
- Node.js | push() function
- JavaScript Array push() Method
- Sending Push Notifications : Progressive Web Apps
- p5.js | Push Operation on Stack
- How to push an array into the object in JavaScript ?
- Alternatives of push() method in JavaScript
- How to use .join() with push and replace together?
- TypeScript | Array push() Method
- How to push elements in an array using AngularJS ?
- How to get the function name inside a function in PHP ?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
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.

