Skip to content
Related Articles

Related Articles

PHP | Ds\Vector remove() Function
  • Last Updated : 22 Aug, 2019

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:

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

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
Recommended Articles
Page :