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 // Declare new Vector $arr = new \Ds\Vector([1, 2, 3, 4, 5, 6]);
echo ( "Vector Elements\n" );
// Display the Vector elements print_r( $arr );
// Use remove() function to // remove Vector elements var_dump( $vector ->remove(1));
echo ( "\n Remove after Elements\n" );
// Display the vector elements print_r( $arr );
?> |
Output:
Vector Elements 1, 2, 3, 4, 5, 6 Remove after Elements 2, 3, 4, 5, 6
Program 2:
PHP
<?php // Declare new Vector $vector = new \Ds\Vector([ "Learn" , "data" , "structures" ]);
echo ( "Vector Elements\n" );
// Display the Vector elements print_r( $vect );
// Use remove() function to // Remove Vector elements var_dump( $vector ->remove(0));
echo ( "\nVector after reversing\n" );
// Display the vector elements 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