Exemple #1
0
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>');
}
Exemple #2
0
function sum($list)
{
    if (empty($list)) {
        return 0;
    }
    return array_shift($list) + sum($list);
}
Exemple #3
0
	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));
	}
Exemple #4
0
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>');
}
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);
}
Exemple #6
0
 function test_sum_initial()
 {
     $sum = sum(4);
     $input = [1, 2, 3];
     $expect = 4 + 1 + 2 + 3;
     $actual = $sum($input);
     $this->assertEquals($actual, $expect);
 }
Exemple #7
0
function average($collection)
{
    $size = size($collection);
    if ($size === 0) {
        return 0;
    } else {
        return sum($collection) / $size;
    }
}
Exemple #8
0
function sum($num)
{
    static $tot;
    //声明静态变量,值可以积累
    if ($num >= 1) {
        $tot += $num;
        return sum(--$num);
        //递归调用函数自身
    } else {
        return $tot;
    }
}
Exemple #9
0
function sum($arr)
{
    $total = 0;
    foreach ($arr as $item) {
        if (is_array($item)) {
            $total += sum($item);
        } elseif (is_numeric($item)) {
            $total += $item;
        }
    }
    return $total;
}
function sum($input)
{
    $total = 0;
    foreach ($input as $value) {
        if (is_array($value)) {
            $total += sum($value);
        } elseif (is_int($value)) {
            $total += $value;
        }
    }
    return $total;
}
Exemple #11
0
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";
    }
}
Exemple #12
0
/**
 * 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;
}
Exemple #13
0
function sum($n)
{
    if ($n <= 0) {
        //Дъно на рекурсията, прекъсва функцията
        return 0;
        //Дъно на рекурсията, прекъсва функцията
    }
    if ($n == 1) {
        //Дъно на рекурсията, прекъсва функцията
        return 1;
        //Дъно на рекурсията, прекъсва функцията
    }
    return $n + sum($n - 1);
}
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;
}
Exemple #15
0
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;
}
Exemple #16
0
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;
}
Exemple #17
0
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);
}
Exemple #18
0
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;
}
Exemple #19
0
    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) {
Exemple #20
0
<?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]);
}
Exemple #21
0
        echo "Число {$x} меньше числа {$y}";
    } elseif ($x > $y) {
        echo "Число {$x} больше числа {$y}";
    } else {
        echo "Число {$x} равно числу {$y}";
    }
}
compare_numbers(5, 8);
echo "<br>";
compare_numbers(rand(1, 100), rand(1, 100));
echo "<hr>";
function sum($u, $h = 10)
{
    return $u + $h;
}
$p = sum(1, 5);
echo "{$p}";
echo "<hr>";
$a = 100;
function sum1($a)
{
    $a++;
    echo "{$a}";
}
echo "{$a}";
//переменная $a
echo "<br>";
sum1($a);
//переменная $a + 1
echo "<br>";
echo "{$a}";
Exemple #22
0
<?php

function xt_sum($a, $b)
{
    return $a + $b;
}
echo xt_sum(4, 5), "\n";
//可变参数
function sum(...$numbers)
{
    $acc = 0;
    foreach ($numbers as $n) {
        $acc += $n;
    }
    return $acc;
}
echo sum(1, 2, 3, 4) . "\n";
//数组解包
echo sum(...[1, 2, 3, 4, 5]) . "\n";
//默认参数
function makecoffee($type = "cappuccino")
{
    return "Making a cup of {$type}.\n";
}
echo makecoffee();
echo makecoffee(null);
echo makecoffee("espresso");
Exemple #23
0
<?php

function sum()
{
    $acc = 0;
    foreach (func_get_args() as $n) {
        // $acc += $n;
        print_r($n);
    }
    return $acc;
}
echo sum(1, 2, 3, 4, 5, 6, 7, 8, 9, "asd");
Exemple #24
0
    }
    $stats = show($dir . "/forum", array("head" => _site_forum, "threads" => _forum_threads, "nthreads" => $allthreads, "posts" => _forum_posts, "nposts" => $allposts, "ppert" => _stats_forum_ppert, "nppert" => $ppert, "pperd" => _stats_forum_pperd, "npperd" => $pperd, "topposter" => _stats_forum_top, "ntopposter" => $topposter));
} elseif ($_GET['action'] == "user") {
    $stats = show($dir . "/user", array("head" => _site_user, "users" => _stats_users_regged, "member" => _stats_users_regged_member, "nmember" => cnt($db['users'], " WHERE level != 1"), "logins" => _stats_users_logins, "nlogins" => sum($db['userstats'], "", "logins"), "msg" => _stats_users_msg, "nmsg" => sum($db['userstats'], "", "writtenmsg"), "votes" => _stats_users_votes, "nvotes" => sum($db['userstats'], "", "votes"), "aktmsg" => _stats_users_aktmsg, "naktmsg" => cnt($db['msg'], " WHERE `von` != '0'"), "buddys" => _stats_users_buddys, "nbuddys" => cnt($db['buddys']), "nusers" => cnt($db['users'])));
} elseif ($_GET['action'] == "cw") {
    if (cnt($db['cw'], " WHERE datum < " . time() . "") != "0") {
        $won = cnt($db['cw'], " WHERE punkte > gpunkte");
        $lost = cnt($db['cw'], " WHERE punkte < gpunkte");
        $draw = cnt($db['cw'], " WHERE datum < " . time() . " && punkte = gpunkte");
        $ges = cnt($db['cw'], " WHERE datum < " . time() . "");
        $wo_p = @round($won * 100 / $ges, 1);
        $lo_p = @round($lost * 100 / $ges, 1);
        $dr_p = @round($draw * 100 / $ges, 1);
    }
    $allp = '<span class="CwWon">' . sum($db['cw'], '', "punkte") . '</span>' . ' : ' . '
             <span class="CwLost">' . sum($db['cw'], '', "gpunkte") . '</span>';
    $stats = show($dir . "/cw", array("head" => _site_clanwars, "played" => _stats_cw_played, "nplayed" => $ges, "won" => _stats_cw_won, "draw" => _stats_cw_draw, "lost" => _stats_cw_lost, "nwon" => $won . " (" . $wo_p . "%)", "ndraw" => $draw . " (" . $dr_p . "%)", "nlost" => $lost . " (" . $lo_p . "%)", "points" => _stats_cw_points, "npoints" => $allp));
} elseif ($_GET['action'] == "awards") {
    $ges = cnt($db['awards']);
    $place_1 = cnt($db['awards'], " WHERE place = 1 ");
    $place_2 = cnt($db['awards'], " WHERE place = 2 ");
    $place_3 = cnt($db['awards'], " WHERE place = 3 ");
    $stats = show($dir . "/awards", array("head" => _site_awards, "p1" => _stats_place . " 1", "p2" => _stats_place . " 2", "p3" => _stats_place . " 3", "p" => _stats_place_misc, "awards" => _stats_awards, "nawards" => $ges, "np1" => $place_1, "np2" => $place_2, "np3" => $place_3, "np" => $ges - $place_1 - $place_2 - $place_3));
} elseif ($_GET['action'] == "mysql") {
    $dbinfo = dbinfo();
    $stats = show($dir . "/mysql", array("head" => _stats_mysql, "size" => _stats_mysql_size, "nsize" => $dbinfo["size"], "entrys" => _stats_mysql_entrys, "nentrys" => $dbinfo["entrys"], "rows" => _stats_mysql_rows, "nrows" => $dbinfo["rows"]));
} elseif ($_GET['action'] == "downloads") {
    $qry = db("SELECT * FROM " . $db['downloads'] . "");
    while ($get = _fetch($qry)) {
        $file = preg_replace("#added...#Uis", "../downloads/files/", $get['url']);
        if (strpos($get['url'], "http://") != 0) {
Exemple #25
0
<?php

/**
 * @author Gutsulyak Vadim <*****@*****.**>
 * @param $a
 * @param $b
 */
function sum($a, $b)
{
    return $a + $b;
}
$result = sum(19, 8);
echo sum(19, 8);
function sumAll()
{
    $args = func_get_args();
    $result = 0;
    foreach ($args as $argument) {
        $result += $argument;
    }
    return $result;
}
echo '<br>';
echo sumAll(10, 4, 5, 8, 43);
Exemple #26
0
<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/12/23
 * Time: 10:04
 */
function scale($a)
{
    return strlen(strstr($a, '.')) - 1;
}
function sum($a, $b)
{
    if (scale($a) > 3 || scale($b) > 3) {
        throw new UnderflowException("Input scale exceeded");
    }
    return $a + $b;
}
echo sum(1, -0.9) . "\n";
echo sum(1, -0.99) . "\n";
echo sum(1, -0.999) . "\n";
echo sum(1, -0.9999) . "\n";
Exemple #27
0
<?php

/**
 * Created by PhpStorm.
 * User: ira
 * Date: 29/12/15
 * Time: 3:39 PM
 */
function sum($x, $y)
{
    /**
     * https://www.jetbrains.com/phpstorm/help/creating-php-documentation-comments.html
     */
    $z = $x + $y;
    echo $z;
    //    return $z;
}
echo "5 + 10 = ", sum(5, 10), "<br>";
sum(5, 10);
/**
 * @param int $a is the *ghgh* of all
 * @param float $b
 * @return int mixed
 */
function poutsa($a, $b)
{
    return $a + $b;
}
Exemple #28
0
{
    global $min, $target;
    $sum = 0;
    $containersFound = 0;
    foreach ($containers as $i => $container) {
        if ($binary[$i] === '1') {
            $sum += $container;
            $containersFound++;
        }
    }
    echo "{$sum}=" . $binary . "\n";
    if ($target === $sum) {
        $min[$containersFound] = $min[$containersFound] + 1;
        return 1;
    }
    return 0;
}
$i = 0;
$total = pow(2, $length);
$found = 0;
for ($i = 0; $i < $total; $i++) {
    $stack = str_pad(decbin($i), $length, '0', STR_PAD_LEFT);
    $found += sum($stack, $containers);
}
echo "part 1: {$found}\n";
foreach ($min as $index => $number) {
    if ($number) {
        echo "part 2: ({$index})" . $number;
        break;
    }
}
Exemple #29
0
<!DOCTYPE html>
<html>
	<body>
		<?php 
function sum($x, $y)
{
    $z = $x + $y;
    return $z;
}
echo "5 + 10 = " . sum(5, 10) . "<br>";
echo "7 + 13 = " . sum(7, 13) . "<br>";
echo "5 + 5 = " . sum(5, 5) . "<br>";
?>
	</body>
</html>
Exemple #30
0
function myName($fname, $year)
{
    echo "{$fname} Ilievici. Born in {$year}\n";
}
myName("Alexei", "1989");
myName("Victor", "1962");
myName("Stepan", "1986");
myName("Marian", "1239");
function sum($x, $y)
{
    $z = $x + $y;
    return $z;
}
echo "5 + 10 = " . sum(5, 10) . "\n";
echo "7 + 13 = " . sum(7, 13) . "\n";
echo "4 + 2 = " . sum(2, 4) . "\n";
function setamGreutate($minheight = 50)
{
    echo "Greutatea este: {$minheight}\n";
}
setamGreutate(350);
setamGreutate();
echo "\narray\n";
$cars = array("Volvo", "BMV", "Toyotta");
echo "I Like " . $cars[0] . ", " . $cars[1] . "and " . $cars[2] . ".\n";
echo count($cars) . "\n";
$carss = array("Volvo", "BMV", "Toyotta");
$arrlenght = count($carss);
//echo "$arrlenght\n";
sort($cars);
for ($c = 0; $c < $arrlenght; $c++) {