本文整理汇总了PHP中sum函数的典型用法代码示例。如果您正苦于以下问题:PHP sum函数的具体用法?PHP sum怎么用?PHP sum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sum函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: vote
function vote($ajax = false)
{
global $db, $balken_vote_menu, $prev;
$qry = db("SELECT * FROM " . $db['votes'] . " WHERE menu = '1' AND forum = 0");
$get = _fetch($qry);
if (_rows($qry)) {
$qryv = db("SELECT * FROM " . $db['vote_results'] . " WHERE vid = '" . $get['id'] . "' ORDER BY what");
while ($getv = _fetch($qryv)) {
$stimmen = sum($db['vote_results'], " WHERE vid = '" . $get['id'] . "'", "stimmen");
if ($stimmen != 0) {
if (ipcheck("vid_" . $get['id']) || isset($_COOKIE[$prev . "vid_" . $get['id']]) || $get['closed'] == 1) {
$percent = round($getv['stimmen'] / $stimmen * 100, 1);
$rawpercent = round($getv['stimmen'] / $stimmen * 100, 0);
$balken = show(_votes_balken, array("width" => $rawpercent));
$votebutton = "";
$results .= show("menu/vote_results", array("answer" => re($getv['sel']), "percent" => $percent, "stimmen" => $getv['stimmen'], "balken" => $balken));
} else {
$votebutton = '<input id="contentSubmitVote" type="submit" value="' . _button_value_vote . '" class="voteSubmit" />';
$results .= show("menu/vote_vote", array("id" => $getv['id'], "answer" => re($getv['sel'])));
}
} else {
$votebutton = '<input id="contentSubmitVote" type="submit" value="' . _button_value_vote . '" class="voteSubmit" />';
$results .= show("menu/vote_vote", array("id" => $getv['id'], "answer" => re($getv['sel'])));
}
}
$vote = show("menu/vote", array("titel" => re($get['titel']), "vid" => $get['id'], "results" => $results, "votebutton" => $votebutton, "stimmen" => $stimmen));
}
return empty($vote) ? '<center style="margin:2px 0">' . _vote_menu_no_vote . '</center>' : ($ajax ? $vote : '<div id="navVote">' . $vote . '</div>');
}
示例2: sum
function sum($list)
{
if (empty($list)) {
return 0;
}
return array_shift($list) + sum($list);
}
示例3: stdev
function stdev(Array $x) {
$n = count($x);
if($n == 0 || ($n - 1) == 0) return null;
$sum = sum($x);
$sumSq = sum_sq($x);
return sqrt(($sumSq - (pow($sum, 2)/$n))/($n - 1));
}
示例4: fvote
function fvote($id, $ajax = false)
{
global $db, $balken_vote_menu, $prev;
if (!permission("votes")) {
$intern = ' AND intern = 0';
}
$qry = db("SELECT * FROM " . $db['votes'] . " WHERE id = '" . $id . "' " . $intern . "");
$get = _fetch($qry);
if (_rows($qry)) {
$qryv = db("SELECT * FROM " . $db['vote_results'] . " WHERE vid = '" . $get['id'] . "' ORDER BY id ASC");
while ($getv = _fetch($qryv)) {
$stimmen = sum($db['vote_results'], " WHERE vid = '" . $get['id'] . "'", "stimmen");
if ($stimmen != 0) {
if (ipcheck("vid_" . $get['id']) || isset($_COOKIE[$prev . "vid_" . $get['id']]) || $get['closed'] == 1) {
$percent = round($getv['stimmen'] / $stimmen * 100, 1);
$rawpercent = round($getv['stimmen'] / $stimmen * 100, 0);
$balken = show(_votes_balken, array("width" => $rawpercent));
$votebutton = "";
$results .= show("forum/vote_results", array("answer" => re($getv['sel']), "percent" => $percent, "stimmen" => $getv['stimmen'], "balken" => $balken));
} else {
$votebutton = '<input id="contentSubmitFVote" type="submit" value="' . _button_value_vote . '" class="voteSubmit" />';
$results .= show("forum/vote_vote", array("id" => $getv['id'], "answer" => re($getv['sel'])));
}
} else {
$votebutton = '<input id="contentSubmitFVote" type="submit" value="' . _button_value_vote . '" class="voteSubmit" />';
$results .= show("forum/vote_vote", array("id" => $getv['id'], "answer" => re($getv['sel'])));
}
}
$qryf = db("SELECT id,kid FROM " . $db['f_threads'] . " WHERE vote = '" . $get['id'] . "'");
$getf = _fetch($qryf);
$vote = show("forum/vote", array("titel" => re($get['titel']), "vid" => $get['id'], "fid" => $getf['id'], "kid" => $getf['kid'], "umfrage" => _forum_vote, "results" => $results, "votebutton" => $votebutton, "stimmen" => $stimmen));
}
return empty($vote) ? '' : ($ajax ? $vote : '<div id="navFVote">' . $vote . '</div>');
}
示例5: karatsuba
function karatsuba($x, $y)
{
$len_x = count($x);
$len_y = count($y);
// bottom of the recursion
if ($len_x == 1 && $len_y == 1) {
return $x[0] * $y[0];
}
if ($len_x == 1 || $len_y == 1) {
$t1 = implode('', $x);
$t2 = implode('', $y);
return (int) $t1 * $t2;
}
$a = array_chunk($x, ceil($len_x / 2));
$b = array_chunk($y, ceil($len_y / 2));
$deg = floor($len_x / 2);
$x1 = $a[0];
// 1
$x2 = $a[1];
// 2
$y1 = $b[0];
// 1
$y2 = $b[1];
// 2
return ($a = karatsuba($x1, $y1)) * pow(10, 2 * $deg) + ($c = karatsuba($x2, $y2)) + (karatsuba(sum($x1, $x2), sum($y1, $y2)) - $a - $c) * pow(10, $deg);
}
示例6: test_sum_initial
function test_sum_initial()
{
$sum = sum(4);
$input = [1, 2, 3];
$expect = 4 + 1 + 2 + 3;
$actual = $sum($input);
$this->assertEquals($actual, $expect);
}
示例7: average
function average($collection)
{
$size = size($collection);
if ($size === 0) {
return 0;
} else {
return sum($collection) / $size;
}
}
示例8: sum
function sum($num)
{
static $tot;
//声明静态变量,值可以积累
if ($num >= 1) {
$tot += $num;
return sum(--$num);
//递归调用函数自身
} else {
return $tot;
}
}
示例9: sum
function sum($arr)
{
$total = 0;
foreach ($arr as $item) {
if (is_array($item)) {
$total += sum($item);
} elseif (is_numeric($item)) {
$total += $item;
}
}
return $total;
}
示例10: sum
function sum($input)
{
$total = 0;
foreach ($input as $value) {
if (is_array($value)) {
$total += sum($value);
} elseif (is_int($value)) {
$total += $value;
}
}
return $total;
}
示例11: postData
function postData($_POST)
{
$matrix = $_POST['item'];
$sum = $matrix[0] + $matrix[4] + $matrix[8];
$max = maximum($matrix);
$t_summ = sum($matrix);
if ($sum == $_POST['result'][0] && $max == $_POST['result'][1] && $t_summ == $_POST['result'][2]) {
echo "YOUR ANSWER IS RIGHT";
} else {
echo "TRY AGAIN";
}
}
示例12: mean
/**
* Return the mean (average) value of the given values.
*
* @param array $values
*
* @return mixed
*/
function mean($values)
{
if (empty($values)) {
return 0;
}
$values = values($values);
$sum = sum($values);
if (0 == $sum) {
return 0;
}
$count = count($values);
return $sum / $count;
}
示例13: sum
function sum($n)
{
if ($n <= 0) {
//Дъно на рекурсията, прекъсва функцията
return 0;
//Дъно на рекурсията, прекъсва функцията
}
if ($n == 1) {
//Дъно на рекурсията, прекъсва функцията
return 1;
//Дъно на рекурсията, прекъсва функцията
}
return $n + sum($n - 1);
}
示例14: sum
function sum($input)
{
$total = 0;
foreach ($input as $value) {
if (is_array($value) || is_object($value)) {
$total += sum($value);
} elseif (is_object($input) && $value === "red") {
return 0;
} elseif (is_int($value)) {
$total += $value;
}
}
return $total;
}
示例15: sum
function sum($n)
{
if ($n >= 1) {
static $sum = 0;
$sum += $n % 10;
$n = ($n - $n % 10) / 10;
sum($n);
}
if ($n < 1) {
echo $sum;
return;
}
return;
}