How PHP calculates the sum of all the values in a multidimensional array, multidimensional arrays
This example describes how PHP calculates the sum of all the values in a multidimensional array. Share to everyone for your reference. The implementation method is as follows:
The PHP built-in function array_sum () function returns the sum of all the values in the array, returning only the sum of one-dimensional arrays;
Calculate all the values of the multidimensional array and the custom function is necessary;
function Get_sum ($array) { $num = 0; foreach ($array as $k = + $v) { if (Is_array ($v)) { $num + = Get_sum ($v); } } return $num + array_sum ($array);} Get_sum ($array);
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1021082.html www.bkjia.com true http://www.bkjia.com/PHPjc/1021082.html techarticle PHP calculates the sum of all the values in a multidimensional array, multidimensional arrays This article describes how PHP calculates the sum of all the values in a multidimensional array. Share to everyone for your reference. Concrete implementation of the party ...