Regarding the method of php recursive function to implement the accumulation of numbers, a small example of php recursive accumulation and summing of numbers, and the method of php recursive function to return the correct accumulated variable.
1. PHP recursive function to realize number accumulation Example: Copy code Code example:2. PHP recursive function cumulative summation php Example of array recursive summation: convert an array, or a two-dimensional array of multiple numbers and return the sum of all values. Example: Copy code Code example:
/*** a flat array ***/ $array = array(10, 20, 5, 34, 129); /*** add the values ***/
echo arraySumRecursive($array)." /*** a multi dimensional array ***/ $array = array(10, 20, 5, array(5, 2, 3, array(5, 3, array(2, 10, array(19, 1) ),3 ), 2, 7 ), 3 ); /*** add the values ***/ echo arraySumRecursive($array); ?> |