The Ds\Vector::remove() function is an inbuilt function in PHP that is used to remove an element from the Vector at the specified $index argument and returns the removed element.
Syntax:
mixed public Ds\Vector::remove( $index )
Parameters: This function does not accept any parameter.
Return Value: The value that was removed.
Below programs illustrate the Ds\Vector::remove() function in PHP:
Program 1:
PHP
<?php
$arr = new \Ds\Vector([1, 2, 3, 4, 5, 6]);
echo ( "Vector Elements\n" );
print_r( $arr );
var_dump( $vector ->remove(1));
echo ( "\n Remove after Elements\n" );
print_r( $arr );
?>
|
Output:
Vector Elements
1, 2, 3, 4, 5, 6
Remove after Elements
2, 3, 4, 5, 6
Program 2:
PHP
<?php
$vector = new \Ds\Vector([ "Learn" , "data" , "structures" ]);
echo ( "Vector Elements\n" );
print_r( $vect );
var_dump( $vector ->remove(0));
echo ( "\nVector after reversing\n" );
print_r( $vect );
?>
|
Output:
Vector Elements
Ds\Vector Object
Learn data structures
Vector after Remove
data structures
Reference: http://php.net/manual/en/ds-vector.reverse.php