The Ds\Deque::reduce() function is an inbuilt function in PHP which is used to reduce the Deque to a single element using callback function.
public Ds\Deque::reduce( $callback, $initial ) : mixed
Parameters: This function accept two parameters as mentioned above and described below:
- callable: It contains the operation to be performed on the elements of Deque resulting into a single element.
- value: It holds the initial value of carry which will be the result after performing operation on all elements.
Return Value: This function returns the final value returned by the callback function.
Below programs illustrate the Ds\Deque::reduce() function in PHP:
Elements of Deque Ds\Deque Object (  => 10  => 20  => 30  => 40  => 50  => 60 ) Deque after reduced into single element: int(215)
Elements of Deque Ds\Deque Object (  => 10  => 20  => 30  => 40  => 50  => 60 ) Deque after reduced into single element: int(8714461220)
- PHP | Ds\Map reduce() Function
- PHP | Ds\Set reduce() Function
- PHP | Ds\Vector reduce() Function
- PHP | Ds\Sequence reduce() Function
- Ways To Reduce The Loading Time Of Your Website | Set 2
- Ways To Reduce The Loading Time Of Website | Set 1
- How to get the function name inside a function in PHP ?
- PHP | min( ) Function
- p5.js | nfs() Function
- PHP | max( ) Function
- PHP Ds\Set sum() 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.