Wednesday, November 26, 2025
HomeLanguagesPHP | DsSequence first() Function

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:




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


Output:

int(10)
string(1) "G"

Example 2:




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


Output:

int(21)
string(1) "G"

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32415 POSTS0 COMMENTS
Milvus
98 POSTS0 COMMENTS
Nango Kala
6792 POSTS0 COMMENTS
Nicole Veronica
11938 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12004 POSTS0 COMMENTS
Shaida Kate Naidoo
6916 POSTS0 COMMENTS
Ted Musemwa
7172 POSTS0 COMMENTS
Thapelo Manthata
6871 POSTS0 COMMENTS
Umr Jansen
6857 POSTS0 COMMENTS