Answers for "php get_sum"

PHP
4

calculate sum (total) of column in php

mysql_connect($hostname, $username, $password);
mysql_select_db($db);

$sql = "select sum(column) from table";
$q = mysql_query($sql);
$row = mysql_fetch_array($q);

echo 'Sum: ' . $row[0];
Posted by: Guest on October-11-2021
1

PHP array sum

<?php
$indexedArray = Array(20, 20, 5.5, "str");
$associativeArray = Array(
    1 => 20,
    2 => 20,
    3 => 5.5,
    4 => "str"
);

echo array_sum($indexedArray) . "<br>"; // 45.5
echo array_sum($associativeArray); // 45.5

?>
Posted by: Guest on September-11-2021

Browse Popular Code Answers by Language