天天看点

php之页面提交与接收

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>

<a target="_blank" href="http://blog.51cto.com/attachment/201308/223924477.jpg"></a>

b.php

&lt;?php

      //接收用户提交的学生的成绩!

      $grades=$_REQUEST['grade'];

      //echo 'grade='.$grades;

      //拆分,对成绩进行分割

      $grades=explode(" ",$grades);

      $allGrades=0;

      //遍历

      foreach($grades as $k=&gt;$v){

             $allGrades+=$v; //隐藏转换 string-&gt;float

            echo  $allGrades;

}

      echo "平均时间是=".$allGrades/count($grades);

?&gt;

<a target="_blank" href="http://blog.51cto.com/attachment/201308/224003611.jpg"></a>

本文转自 gjp0731 51CTO博客,原文链接:http://blog.51cto.com/guojiping/1283889