PHP | Ds\Vector reversed() Function
The Ds\Vector::reversed() function is an inbuilt function in PHP which is used to reverse the elements of vector after copying the elements of original vector into a copy.
Syntax:
public Ds\Vector::reversed( void ) : Ds\Vector
Parameters: This function does not accept any parameter.
Return Value: This function returns a copy of the original vector in reverse order. Also, the original vector will have no effect.
Below is the program to illustrate the Ds\Vector::reversed() function in PHP:
Program 1:
<?php // Create new Vector $arr = new \Ds\Vector([1, 2, 3, 4, 5]); // Display the elements var_dump($arr); echo("Vector after reversing\n"); // Use reversed() function to reverse // the copy of vector and display it var_dump($arr->reversed()); ?> |
Output:
object(Ds\Vector)#1 (5) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
}
Vector after reversing
object(Ds\Vector)#2 (5) {
[0]=>
int(5)
[1]=>
int(4)
[2]=>
int(3)
[3]=>
int(2)
[4]=>
int(1)
}
Program 2:
<?php // Create new Vector $arr = new \Ds\Vector(["Learn", "data", "structures"]); // Display the elements print_r($arr); echo("Vector after reversing\n"); // Use reversed() function to reverse // the copy of vector and display it print_r($arr->reversed()); ?> |
Output:
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.reversed.php
Recommended Posts:
- PHP Ds\Set reversed() Function
- PHP | Ds\Map reversed() Function
- PHP | Ds\Sequence reversed() Function
- PHP | Ds\Deque reversed() Function
- HTML | DOM Ol reversed Property
- HTML | reversed Attribute
- HTML | <ol> reversed Attribute
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- PHP | min( ) Function
- PHP | max( ) Function
- D3.js | d3.sum() function
- CSS | url() Function
- D3.js | d3.mean() function
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.



