How to use array reduce in PHP

In this article, I will explain how the array_reduce() function can be used in PHP.
  • 1930

array_reduce() function in PHP

  • The array_reduce() function is used to sends the values in an array to a user-defined function, and returns a string.

  • In array_reduce() function, If the optional initial is available, it will be used at the beginning of the process.




  • array  array is required parameter. Specifies an array.

  • function number is required parameter.  User define function for input the value in array.

  • initial initial is optional parameter. determine the initial value to send to the function


The following example show to how the array_reduce() function can be used in PHP.



<h3 style="color: red;">array_reduce() function example in PHP</h3>  


    function add($a1, $a2) 


    $a1 += $a2; 

    return $a1; 


    $array1 = array(1, 2,3,4,5); 


    echo " value is : ".$x; 







You may also want to read these related articles here
Ask Your Question 
Got a programming related question? You may want to post your question here


More Articles

© 2020 DotNetHeaven. All rights reserved.