天天看點

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