PHP | Ds\Sequence push() Function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
?>

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
?>

chevron_right


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




My Personal Notes arrow_drop_up

Image
Check out this Author's contributed articles.

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.