Thursday, September 4, 2025
HomeLanguagesPHP | DsVector remove() Function

PHP | Ds\Vector remove() Function

The Ds\Vector::remove() function is an inbuilt function in PHP which is used to remove the value from index and return it.

Syntax:

public Ds\Vector::remove( $index ) : mixed

Parameters: This function accepts single parameter $index which holds the index at which the element is to be removed.

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

Exception: This function throws OutOfRangeException if the given index is out of range or not valid.

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

Program 1:




<?php
  
// Declare new vector
$vect = new \Ds\Vector(["neveropen", "for",
            "neveropen", "DataStructures"]);
  
echo("Vector Elements\n");
  
// Display the Vector elements
print_r($vect);
  
echo("\nLast element of the vector: \n");
  
// Use remove() function to remove 
// value at index 3 and return it
var_dump($vect->remove(3));
  
?>


Output:

Vector Elements
Ds\Vector Object
(
    [0] => neveropen
    [1] => for
    [2] => neveropen
    [3] => DataStructures
)

Last element of the vector: 
string(14) "DataStructures"

Program 2:




<?php
  
// Declare new vector
$vect = new \Ds\Vector([1, 2, 3, 4, 5, 6]);
  
echo("Vector Elements\n");
  
// Display the Vector elements
print_r($vect);
  
echo("\nLast element of the vector: \n");
  
// Use remove() function to remove 
// value at index 3 and return it
var_dump($vect->remove(3));
  
?>


Output:

Vector Elements
Ds\Vector Object
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
)

Last element of the vector: 
int(4)

Reference: http://php.net/manual/en/ds-vector.remove.php

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32263 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11857 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6696 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS