• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP sum函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中sum函数的典型用法代码示例。如果您正苦于以下问题:PHP sum函数的具体用法?PHP sum怎么用?PHP sum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sum函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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>');
}
开发者ID:nopuls,项目名称:dzcp,代码行数:29,代码来源:vote.php


示例2: sum

function sum($list)
{
    if (empty($list)) {
        return 0;
    }
    return array_shift($list) + sum($list);
}
开发者ID:brslv,项目名称:code,代码行数:7,代码来源:index.php


示例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));
	}
开发者ID:revned,项目名称:orangephp,代码行数:7,代码来源:Helpers.php


示例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>');
}
开发者ID:nopuls,项目名称:dzcp,代码行数:34,代码来源:fvote.php


示例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);
}
开发者ID:Baft,项目名称:Algorithm-and-Data-Structure-in-PHP,代码行数:26,代码来源:karatsubaMultiplication.php


示例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);
 }
开发者ID:morrisonlevi,项目名称:algorithm,代码行数:8,代码来源:SumTest.php


示例7: average

function average($collection)
{
    $size = size($collection);
    if ($size === 0) {
        return 0;
    } else {
        return sum($collection) / $size;
    }
}
开发者ID:mpetrovich,项目名称:dash,代码行数:9,代码来源:average.php


示例8: sum

function sum($num)
{
    static $tot;
    //声明静态变量,值可以积累
    if ($num >= 1) {
        $tot += $num;
        return sum(--$num);
        //递归调用函数自身
    } else {
        return $tot;
    }
}
开发者ID:denson7,项目名称:phpstudy,代码行数:12,代码来源:4_recursion.php


示例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;
}
开发者ID:JimMackin,项目名称:AdventOfCode,代码行数:12,代码来源:day12-1.php


示例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;
}
开发者ID:DaveWishesHe,项目名称:adventofcode-solutions,代码行数:12,代码来源:12-1.php


示例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";
    }
}
开发者ID:shogher,项目名称:php_examples,代码行数:12,代码来源:functions.php


示例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;
}
开发者ID:hason,项目名称:tabular,代码行数:20,代码来源:functions.php


示例13: sum

function sum($n)
{
    if ($n <= 0) {
        //Дъно на рекурсията, прекъсва функцията
        return 0;
        //Дъно на рекурсията, прекъсва функцията
    }
    if ($n == 1) {
        //Дъно на рекурсията, прекъсва функцията
        return 1;
        //Дъно на рекурсията, прекъсва функцията
    }
    return $n + sum($n - 1);
}
开发者ID:Just-Man,项目名称:PHP,代码行数:14,代码来源:Function_Sum.php


示例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;
}
开发者ID:DaveWishesHe,项目名称:adventofcode-solutions,代码行数:14,代码来源:12-2.php


示例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;
}
开发者ID:kutniyan,项目名称:HomeTasks,代码行数:14,代码来源:index.php


示例16: sum

function sum($arr)
{
    $total = 0;
    if (is_red($arr)) {
        return 0;
    }
    foreach ($arr as $item) {
        if (is_red($item)) {
            continue;
        }
        if (is_array($item)) {
            $total += sum($item);
        } elseif (is_numeric($item)) {
            $total += $item;
        }
    }
    return $total;
}
开发者ID:JimMackin,项目名称:AdventOfCode,代码行数:18,代码来源:day12-2.php


示例17: sum

function sum($arr, $level = 0)
{
    static $items;
    static $count;
    if (is_array($arr)) {
        $level++;
        foreach ($arr as $value) {
            //                      echo '<pre>';
            //                      print_r($arr);
            //                      echo '</pre>';
            sum($value, $level);
        }
    } else {
        //echo '<br> не масив';
        $count++;
        $items += $arr;
    }
    return array('count' => $count, 'item' => $items);
}
开发者ID:naelrouz,项目名称:phpStartVZ0,代码行数:19,代码来源:6.php


示例18: sum

function sum()
{
    $args = func_get_args();
    $s = 0;
    foreach ($args as $arg) {
        if (is_array($arg)) {
            foreach ($arg as $value) {
                if (is_array($value)) {
                    $s += sum($value);
                } else {
                    $s += $value;
                }
            }
        } else {
            $s += $arg;
        }
    }
    return $s;
}
开发者ID:hunglmtb,项目名称:eb,代码行数:19,代码来源:FormulaHelpers.php


示例19: sum

    echo "{$value} <br>";
}
?>
<br />

<!-- PHP Functions -->
Function names are NOT case-sensitive. <br />

<?php 
function sum($x, $y = 0)
{
    $z = $x + $y;
    return $z;
}
echo "5 + _ = " . sum(5) . "<br>";
echo "7 + 13 = " . sum(7, 13) . "<br>";
?>
<br />

<!-- PHP Arrays -->
In PHP, there are three types of arrays: <br />
Indexed arrays - Arrays with a numeric index <br />
Associative arrays - Arrays with named keys <br />
Multidimensional arrays - Arrays containing one or more arrays <br />

<?php 
$cars = array("Volvo", "BMW", "Toyota");
echo count($cars);
echo "<br />";
$age = array("Peter" => "35", "Ben" => "37", "Joe" => "43");
foreach ($age as $x => $x_value) {
开发者ID:pepincho,项目名称:playground,代码行数:31,代码来源:init.php


示例20: sum

<?php

function sum($array)
{
    $firstNumber = $array[0];
    $secondNumber = $array[1];
    $sum = $firstNumber + $secondNumber;
    printf('$firstNumber + $secondNumber = %.2f + %.2f = %.2f' . "\n", $firstNumber, $secondNumber, $sum);
}
$input = [[2, 5], [1.567808, 0.356], [1234.5678, 333]];
for ($i = 0; $i < count($input); $i++) {
    sum($input[$i]);
}
开发者ID:nok32,项目名称:SoftUni,代码行数:13,代码来源:SumTwoNumbers.php



注:本文中的sum函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP sumo_get_message函数代码示例发布时间:2022-05-23
下一篇:
PHP suivre_invalideur函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap