Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP array_reduce() Function

PHP array_reduce() Function

PHP Array ReferenceComplete PHP Array Reference Manual

Example

Send the values of an array to a user-defined function and return a string:

Run Example »


Definition and Usage

The array_reduce() function sends the values of an array to a user-defined function and returns a string.

**Note:** If the array is empty or no initial value is passed, the function returns NULL.


Syntax

array_reduce(

array,myfunction,initial

)

Parameters Description
array Required. Specifies the array.
myfunction Required. Specifies the name of the function.
initial Optional. Specifies the first value sent to the function for processing.

Technical Details

Return Value: Returns the resulting value.
PHP Version: 4.0.5+
Changelog: Since PHP 5.3.0, theinitial parameter accepts multiple types (mixed); versions before PHP 5.3.0 only supported integers.

More examples

Example 1

With the initial parameter:

Run Example »

Example 2

Return the total sum:

Run Example »


PHP Array ReferenceComplete PHP Array Reference Manual