Friday, October 17, 2025
HomeLanguagesPHP | DsSet last() Function

PHP | Ds\Set last() Function

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

Syntax:  

void public Ds\Set::last( void ) 

Parameter: This function does not accept any parameter.

Return Value: This function returns the last value of the Set.

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

Program 1:  

PHP




<?php
 
// PHP program to illustrate the
// Ds\set::last() function
 
// Create a set instance
$set = new \Ds\Set();
 
// Adding elements to Set
$set->add("Welcome");
$set->add("to");
$set->add("GfG");
 
// Print the last element from set
print_r($set->last());
 
?>


Output: 

GfG

 

Program 2: 

PHP




<?php
 
// PHP program to illustrate the
// Ds\set::last() function
 
// Create a set instance
$set = new \Ds\Set();
 
// Adding elements to Set
$set->add("10");
$set->add("20");
$set->add("30");
 
// Print the last element from set
print_r($set->last());
 
?>


Output: 

30

 

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

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS