Javatpoint Logo
Javatpoint Logo

PHP array_reduce() function

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





Help Others, Please Share

facebook twitter pinterest