PHP | Ds\Sequence last() Function

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

Syntax:

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

Parameters: This function does not accept any values.

Return Value: This function returns the last element from the sequence.

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

Program 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 last element from the sequence
var_dump($seq->last());
   
// Create new sequence
$seq new \Ds\Vector(['G', 'e', 'e', 'k', 's']);
   
// Display the last element from the sequence
var_dump($seq->last());
   
?>

chevron_right


Output:

int(25)
string(1) "s"

Program 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 last element
// from the sequence
var_dump($seq->last());
   
// Function to push an element
$seq->insert(4, "G");   
   
// Display the last element
// from the sequence
var_dump($seq->last());
   
?>

chevron_right


Output:

string(1) "x"
string(1) "G"

Reference: http://php.net/manual/en/ds-sequence.last.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.