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 使用Callable Closure强制指定回调类型
这篇文章主要介绍了详解php 使用Callable Closure强制指定回调类型的相关资料,希望通过本文能帮助到大家,需要的朋友可以参考下2017-10-10php调用Google translate_tts api实现代码
以下是对php调用Google translate_tts api的实现代码进行了分析介绍,需要的朋友可以过来参考下2013-08-08PHP move_uploaded_file() 函数(将上传的文件移动到新位置)
这篇文章主要介绍了PHP move_uploaded_file() 函数,其实就是将上传的文件移动到新位置,需要的朋友可以参考下2018-03-03
最新评论