Php calculates the sum of all values in a multi-dimensional array. Php calculates the sum of all values in the multi-dimensional array. the array_sum () function of the php built-in function of the multi-dimensional array returns the sum of all values in the array. only the sum of one-dimensional arrays can be returned; calculate the sum of all values in the multi-dimensional array by using the multi-dimensional php.
The php built-in function array_sum () returns the sum of all values in the array. only the sum of one-dimensional arrays can be returned;
To calculate the sum of all values of a multi-dimensional array, you must use a custom function;
1 function get_sum ($ array) {2 $ num = 0; 3 foreach ($ array as $ k => $ v) {4 if (is_array ($ v )) {5 $ num + = get_sum ($ v); 6} 7} 8 return $ num + array_sum ($ array); 9}
10 get_sum ($ array );
The http://www.bkjia.com/PHPjc/1018253.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1018253.htmlTechArticlephp calculates the sum of all values in the multi-dimensional array, the multi-dimensional array php built-in function array_sum () function returns the sum of all values in the array, can only return the sum of one-dimensional array; calculate the number of multi-dimensional...