a.php
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
</head>
<body>
<h1>请输入五个小孩的成绩,用空格隔开</h1>
<form action="b.php" method="post">
<input type="text" name="grade"/>
<input type="submit" value="开始统计"/>
</form>
</body>
</html>
b.php
<?php
//接收用户提交的学生的成绩!
$grades=$_REQUEST['grade'];
//echo 'grade='.$grades;
//拆分,对成绩进行分割
$grades=explode(" ",$grades);
$allGrades=0;
//遍历
foreach($grades as $k=>$v){
$allGrades+=$v; //隐藏转换 string->float
echo $allGrades;
}
echo "平均时间是=".$allGrades/count($grades);
?>
转载于:https://blog.51cto.com/guojiping/1283889