Friday, October 10, 2025
HomeLanguagesPHP | DsSequence remove() Function

PHP | Ds\Sequence remove() Function

The Ds\Sequence::remove() function is an inbuilt function in PHP which is used to remove and return a value by index.

Syntax:

mixed abstract public Ds\Sequence::remove ( int $index )

Parameters: This function accepts a single parameter $index which holds the index of value to remove.

Return value: This function returns the value that was removed.

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

Program 1:




<?php
  
// Declare a sequence
$seq = new \Ds\Vector(["Geeks", "Hello", "GFG"]);
  
// Use remove() function
var_dump($seq->remove(2));
var_dump($seq->remove(0));
  
?>


Output:

string(3) "GFG"
string(5) "Geeks"

Program 2:




<?php
  
// Declare a sequence
$seq = new \Ds\Vector([1, 3, 5, 7, 8, 9]);
  
// Use remove() function
$seq->remove(5);
$seq->remove(3);
$seq->remove(2);
$seq->remove(0);
  
var_dump($seq->remove(1));
  
?>


Output:

int(8)

Reference: https://www.php.net/manual/en/ds-sequence.remove.php

RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS