What is the Ds\Vector::reverse() function in PHP?
Ds\Vector::reverse() is a built-in function in PHP.
The function reverses a specified vector array
Syntax
The following is the function prototype:
public void Ds\Vector::reverse (void)
Parameters and return value
The Ds\Vector::reverse() function does not take any input parameters, as the vector is reversed in place.
Since the function has a return of type void, nothing is returned.
Code
The following code demonstrates how we can use the reverse function.
<?php
// Create new Vector
$vector = new \Ds\Vector([2, 3, 5, 7, 11]);
// Print original vector
print_r($vector);
echo("Vector after reversing\n");
// Use reverse() function to reverse the vector
$vector->reverse();
print_r($vector);
?>
Output
Ds\Vector Object
(
[0] => 2
[1] => 3
[2] => 5
[3] => 7
[4] => 11
)
Vector after reversing
Ds\Vector Object
(
[0] => 11
[1] => 7
[2] => 5
[3] => 3
[4] => 2
)
Note: To run this program, you must first install Data Structures for PHP on your local machine.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved