-
Notifications
You must be signed in to change notification settings - Fork 0
/
statistics2.php
84 lines (76 loc) · 2.28 KB
/
statistics2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/***/
session_name('test');
session_start();
function start_init()
{
$_SESSION['count'] = 0;
$_SESSION['sum'] = 0;
$_SESSION['min'] = INF;
$_SESSION['max'] = -1;
}
//$_SESSION['count'] = @$_SESSION['count'] + 1;
//unset($_SESSION['count']);
//$_SESSION = array();
//session_destroy();
if (!isset($_SESSION['count']))
{
start_init();
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link href="assets/css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
<script src="assets/jquery-3.2.1.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<form action="#" method="post">
<input class="form-control form-control-lg" type="text" placeholder=".form-control-lg" name="number"><br>
<button type="submit" class="btn btn-primary" name="go">Submit</button>
</form>
<?
if (isset($_POST['go']))
{
$number = $_POST['number'];
echo $number.'<br>';
if ($number > 0)
{
$_SESSION['count']++;
$_SESSION['sum'] += $number;
// if ($_SESSION['count']==1)
// {
// $_SESSION['min'] = $number;
// $_SESSION['max'] = $number;
// }
// else
// {
// if ($_SESSION['min'] > $number) $_SESSION['min'] = $number;
// if ($_SESSION['max'] < $number) $_SESSION['max'] = $number;
// }
if ($_SESSION['min'] > $number) $_SESSION['min'] = $number;
if ($_SESSION['max'] < $number) $_SESSION['max'] = $number;
}
elseif ( $number == 0 && $_SESSION['count']!=0 )
{
echo 'Кол-во всех чисел = '.$_SESSION['count'].'<br>';
echo 'Сумма всех чисел = '.$_SESSION['sum'].'<br>';
echo 'min = '.$_SESSION['min'].'<br>';
echo 'max = '.$_SESSION['max'].'<br>';
echo 'Среднее арифметическое чисел = '.$_SESSION['sum']/$_SESSION['count'].'<br>';
start_init();
}
elseif ($number < 0)
{
echo ' Error. $number must be > 0 <br>';
}
}
?>
</body>
</html>