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