Php calculates the sum of all values in a multi-dimensional array. Php calculates the sum of all values in a multi-dimensional array. This article describes how php calculates the sum of all values in a multi-dimensional array. Share it with you for your reference. Specifically, php calculates the sum of all values in a multi-dimensional array.
This example describes how php calculates the sum of all values in a multi-dimensional array. Share it with you for your reference. The specific implementation method is as follows:
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;
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 will help you with php programming.
Examples in this article describes how php calculates the sum of all values in a multi-dimensional array. Share it with you for your reference. Implementation...