php表单请求获得数据求和示例
更新时间:2014年05月15日 15:15:14 作者:
这篇文章主要介绍了php表单请求获得数据求和实现代码,需要的朋友可以参考下
获得表单请求的值:
案例:
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);//以空格拆分字符串,并得到数组结果
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);//以空格拆分字符串,并得到数组结果
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函数nl2br()与自定义函数nl2p()换行用法分析
这篇文章主要介绍了PHP函数nl2br()与自定义函数nl2p()换行用法,结合实例形式分析PHP函数nl2br实现换行功能的优缺点及自定义函数nl2p换行功能的使用技巧,需要的朋友可以参考下2016-04-04


最新评论