PHP | Ds\Vector reversed() Function
Last Updated :
29 Jan, 2019
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
$arr = new \Ds\Vector([1, 2, 3, 4, 5]);
var_dump( $arr );
echo ( "Vector after reversing\n" );
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
$arr = new \Ds\Vector([ "Learn" , "data" , "structures" ]);
print_r( $arr );
echo ( "Vector after reversing\n" );
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
Share your thoughts in the comments
Please Login to comment...