PHP | Ds\Vector push() Function
The Ds\Vector::push() function is an inbuilt function in PHP which is used to add elements to the end of the vector.
Syntax:
void public Ds\Vector::push( $values )
Parameters: This function accepts a single parameter $values which contains one or more then one elements to be added to the vector.
Return Value: This function does not return any values.
Below programs illustrate the Ds\Vector::push() function in PHP:
Program 1:
<?php // Create new vector $arr1 = new \Ds\Vector([10, 20, 30, 40, 50]); echo("Original vector elements\n"); print_r($arr1); // Use push() function to add // element to the vector $arr1->push(60); echo("\nVector after appending the elements\n"); print_r($arr1); ?> |
Output:
Original vector elements
Ds\Vector Object
(
[0] => 10
[1] => 20
[2] => 30
[3] => 40
[4] => 50
)
Vector after appending the elements
Ds\Vector Object
(
[0] => 10
[1] => 20
[2] => 30
[3] => 40
[4] => 50
[5] => 60
)
Program 2:
<?php // Create new vector $arr1 = new \Ds\Vector([10, 20, 30, 40, 50]); echo("Original vector elements\n"); print_r($arr1); // Use push() function to add // element to the vector $arr1->push(...[60, 70]); echo("\nVector after appending the elements\n"); print_r($arr1); ?> |
Output:
Original vector elements
Ds\Vector Object
(
[0] => 10
[1] => 20
[2] => 30
[3] => 40
[4] => 50
)
Vector after appending the elements
Ds\Vector Object
(
[0] => 10
[1] => 20
[2] => 30
[3] => 40
[4] => 50
[5] => 60
[6] => 70
)
Reference: http://php.net/manual/en/ds-vector.push.php
Recommended Posts:
- PHP | Ds\Stack push() Function
- PHP | Ds\Sequence push() Function
- PHP | SplDoublyLinkedList push() Function
- PHP | Ds\Deque push() Function
- Node.js | push() function
- PHP Ds\PriorityQueue push() Function
- PHP Ds\Queue push() Function
- p5.js | Push Operation on Stack
- How to push an array into the object in JavaScript ?
- Sending Push Notifications : Progressive Web Apps
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- PHP | min( ) Function
- PHP | Ds\Set xor() Function
- p5.js | nf() 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.



