Saturday, July 25, 2026
HomeLanguagesPHP | DsSet first() Function

PHP | Ds\Set first() Function

The Ds\Set::first() function is an inbuilt function in PHP which returns the first element of the Set.

Syntax:  

void public Ds\Set::first( void )

Parameter: This function does not accept any parameter.

Return value: This function returns the first value of the Set.

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

Program 1:  

PHP




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


Output: 

Welcome

 

Program 2

PHP




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


Output: 

10

 

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

RELATED ARTICLES

6 COMMENTS

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6972 POSTS0 COMMENTS