Friday, May 15, 2026
HomeLanguagesPHP | DsSequence last() Function

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:

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

Parameters: This function does not accept any parameters.

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

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

Program 1:




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


Output:

int(25)
string(1) "s"

Program 2:




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


Output:

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

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

RELATED ARTICLES

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS