PHP | Ds\Vector remove() Function

The Ds\Vector::remove() function is an inbuilt function in PHP which is used to reverse the elements of the vector in-place. For example, if the vector elements are [1, 2, 3, 4, 5], then it will be reversed as [5, 4, 3, 2, 1].

Syntax:

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

Parameters: This function does not accept any parameter.

Return Value: This function does not return any value.

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

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Declare new Vector
$arr = new \Ds\Vector([1, 2, 3, 4, 5, 6]);
  
echo("Vector Elements\n");
  
// Desplay the Vector elements
var_dump($arr);
  
// Use reverse() function to 
// reverse Vector elements
$arr->reverse();
  
echo("\nVector after reversing\n");
  
// Display the vector elements
var_dump($arr);
  
?>

chevron_right


Output:

Vector Elements
object(Ds\Vector)#1 (6) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
  [4]=>
  int(5)
  [5]=>
  int(6)
}

Vector after reversing
object(Ds\Vector)#1 (6) {
  [0]=>
  int(6)
  [1]=>
  int(5)
  [2]=>
  int(4)
  [3]=>
  int(3)
  [4]=>
  int(2)
  [5]=>
  int(1)
}

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Declare new Vector
$vect = new \Ds\Vector(["Learn", "data", "structures"]);
  
echo("Vector Elements\n");
  
// Desplay the Vector elements
print_r($vect);
  
// Use reverse() function to 
// reverse Vector elements
$vect->reverse();
  
echo("\nVector after reversing\n");
  
// Display the vector elements
print_r($vect);
  
?>

chevron_right


Output:

Vector Elements
Ds\Vector Object
(
    [0] => Learn
    [1] => data
    [2] => structures
)

Vector after reversing
Ds\Vector Object
(
    [0] => structures
    [1] => data
    [2] => Learn
)

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.