PHP | Ds\Sequence first() Function

The Ds\Sequence::first() function is an inbuilt function in PHP which is used to return the first element from the sequence.

Syntax:

mixed abstract public Ds\Sequence::first ( void )

Parameter: This function does not accepts any parameter.

Return value: This function returns the first element from the sequence.

Below programs illustrate the Ds\Sequence::first() function in PHP:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create new sequence
$seq new \Ds\Vector([10, 20, 13, 25]);
  
// Display the first element from the sequence
var_dump($seq->first());
  
// Create new sequence
$seq new \Ds\Vector(['G', 'e', 'e', 'k', 's']);
  
// Display the first element from the sequence
var_dump($seq->first());
  
?>

chevron_right


Output:

int(10)
string(1) "G"

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create new sequence
$seq new \Ds\Vector([21, 23, 'p', 'x']);
  
// Display the first element
// from the sequence
var_dump($seq->first());
  
// Function to push an element
$seq->insert(0, "G");   
  
// Display the first element
// from the sequence
var_dump($seq->first());
  
?>

chevron_right


Output:

int(21)
string(1) "G"

Reference: http://php.net/manual/en/ds-sequence.first.php



My Personal Notes arrow_drop_up

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.