arrays, if you have experienced programming in other languages, you will be familiar with the concept of arrays. Because of the array, you can refer to a series of variables with the same name and identify them with numbers (indexes). In many cases, using arrays can shorten and simplify the program, because you can use index values to design a loop to efficiently handle many situations. The array has upper and lower bounds, and the elements of the array are contiguous within the upper bound.
multidimensional arrays, which sometimes require tracking information in an array of records. For example, to keep track of every pixel on your computer screen, you need to reference its X, Y coordinates. You should store the values in a multidimensional array.
This article mainly introduces the method of PHP to calculate the sum of all the values in multidimensional array, and it involves the technique of PHP recursive invocation for multidimensional arrays.
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);