php表單請求獲得數(shù)據(jù)求和示例
更新時間:2014年05月15日 15:15:14 作者:
這篇文章主要介紹了php表單請求獲得數(shù)據(jù)求和實現(xiàn)代碼,需要的朋友可以參考下
獲得表單請求的值:
案例:
request.php
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8;" />
<title>計算請求</title>
</head>
<body>
<form action="result.php" method="post">
<input type="text" name="grade"/>
<input type="submit" value="開始計算"/>
</form>
</body>
</html>
[code]
result.php
[code]
<?php
$grade=$_REQUEST['grade'];//grade-->和表單中的name值一樣
$arr=explode(" ",$grade);//以空格拆分字符串,并得到數(shù)組結果
print_r($arr);
$res=0;
for($i=0;$i<count($arr);$i++){
$res+=$arr[$i];
}
echo "<br/>ALL=".$res;
echo "<br/>AVG=".(round($res/count($arr),0));//round(12.334,2)//四舍五入的方法
?>
案例:
request.php
復制代碼 代碼如下:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8;" />
<title>計算請求</title>
</head>
<body>
<form action="result.php" method="post">
<input type="text" name="grade"/>
<input type="submit" value="開始計算"/>
</form>
</body>
</html>
[code]
result.php
[code]
<?php
$grade=$_REQUEST['grade'];//grade-->和表單中的name值一樣
$arr=explode(" ",$grade);//以空格拆分字符串,并得到數(shù)組結果
print_r($arr);
$res=0;
for($i=0;$i<count($arr);$i++){
$res+=$arr[$i];
}
echo "<br/>ALL=".$res;
echo "<br/>AVG=".(round($res/count($arr),0));//round(12.334,2)//四舍五入的方法
?>
相關文章
PHP函數(shù)nl2br()與自定義函數(shù)nl2p()換行用法分析
這篇文章主要介紹了PHP函數(shù)nl2br()與自定義函數(shù)nl2p()換行用法,結合實例形式分析PHP函數(shù)nl2br實現(xiàn)換行功能的優(yōu)缺點及自定義函數(shù)nl2p換行功能的使用技巧,需要的朋友可以參考下2016-04-04
PHP+Mysql+jQuery實現(xiàn)動態(tài)展示信息
在本文中,我將介紹如何在頁面上實現(xiàn)動態(tài)展示用戶發(fā)表的信息,將用戶發(fā)表的信息逐條播放展示。該效果可以在展示系統(tǒng)動態(tài)、商品評論等場景應用2011-10-10
php實現(xiàn)將任意進制數(shù)轉換成10進制的方法
這篇文章主要介紹了php實現(xiàn)將任意進制數(shù)轉換成10進制的方法,涉及php數(shù)制轉換的相關技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04

