PHP array_reduce() Function
Last Updated : 17 Mar 2025
The array_reduce() function is a inbuilt function of PHP. The array_reduce( ) function is used to reduce the array to a single value using a callback function. This function was introduced in PHP 4.0.5.
Syntax
Parameter
| Parameter | Description | Is compulsory |
|---|---|---|
| array | Specifies an array. | compulsory |
| User defined function | User supplied function to accept values from the array. | compulsory |
| Initial_value | Initial value to send to the function. | Optional |
Return type
The array_reduce( ) function returns the reduced result. It can be of any type int, float or string.
Example 1
Output:
6-PHP-java-python
Example 2
Output:
21
Example 3
Output:
start and 15 and 120 and 45 and 320
Example 4
Output:
120000
Next TopicPhp-array-replace-function