How PHP calculates the sum of the data in a field of MySQL
Reply content:
How PHP calculates the sum of the data in a field of MySQL
SELECT sum(`field_name`) FROM `table`
Now that you can use MySQL, why not just use the sum of MySQL?
PHP Write a foreach loop compile it again
Ask the question of the Lord, MySQL's sum is more efficient, or PHP's foreach faster.
The sum of the foreach computed data
foreach ($income as $key = = $val) {
$total+= $val['xx']; }
The sum () function of MySQL
Yes, why not use the SUM
function, the select SUM('field') where ...
data is a special point with some of the functions of MySQL in the format of a bit.
If it is a one-dimensional array direct array_sum
If it is a two-dimensional array can use Array_column, array_sum to do
It feels good to do it through MySQL.
It is usually an array, the direct count ($data) can find the total number of data