The Ds\Vector::reduce() function is an inbuilt function in PHP which reduce the vector to single value by applying operations in the callback function.
public Ds\Vector::reduce( $callback, $initial ) : mixed
Parameters: This function accepts two parameters as mentioned above and described below:
- $callback: This parameter holds the function which contains the operation on the elements and store carry. This callback function contains two arguments, carry and value, where carry is the value returned by the function and value is the value of element at current iteration.
- $initial: This parameter holds the initial value of carry, which can be NULL.
Return Value: This function returns the final value returned by the callback function.
Below programs illustrate the Ds\Vector::reduce() function in PHP:
Vector Elements Ds\Vector Object (  => 1  => 2  => 3  => 4  => 5 ) Element after performing operation int(25)
Original vector elements Ds\Vector Object (  => 10  => 20  => 30  => 40  => 50 ) Vector after reducing to single element int(120000000)
- PHP | Ds\Map reduce() Function
- PHP | Ds\Set reduce() Function
- PHP | Ds\Sequence reduce() Function
- PHP | Ds\Deque reduce() Function
- Ways To Reduce The Loading Time Of Website | Set 1
- Ways To Reduce The Loading Time Of Your Website | Set 2
- p5.js | pow() function
- D3.js | d3.map.has() Function
- PHP | each() Function
- D3.js | d3.set.has() Function
- PHP | pos() Function
- D3.js | d3.map.get() Function
- D3.js | d3.lab() 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 firstname.lastname@example.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.