php教程--案例3
发布日期:2021-05-06 21:10:16 浏览次数:19 分类:原创文章

本文共 1069 字,大约阅读时间需要 3 分钟。

<?phpheader("Content-type:text/html;charset=utf-8");//定义变量$name = '小明';$score = 0;$str = '';//点击提交按钮,随机成绩和姓名if($_POST['rand_score']){    //姓名数组    $array_name = array( '0'=>'小明','1'=>'小红','2'=>'小熊','3'=>'小娜','4'=>'小蛋','5'=>'小皮');    //随机姓名    $temp = rand(0,5);    $name = $array_name[$temp];    //随机成绩    $score = rand(0,100);}//判断成绩是否输入为整数或者浮点数if(is_int($score) || is_float($score)){    if($score >= 90 && $score <= 100)    {        $str = "A";    }    elseif($score >= 80 && $score < 90)    {        $str = "B";    }    elseif($score >= 70 && $score <80)    {        $str = "C";    }    elseif($score >= 60 && $score <70)    {        $str = "D";    }    elseif($score >= 0 && $score <60)    {        $str = "E";    }    else    {        $str = "输入学生成绩数值范围有误!";    }}echo "<h2>学生成绩等级</h2>";echo "<p>姓名:{$name}</p>";echo "<p>分数: {$score}分</p>";echo "<p>成绩等级:<strong>{$str}级</strong></p>";echo "<hr>";//提交按钮必须在form表单内,action处理页面本页负责echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>";echo "<input type='submit' name='rand_score' value='随机成绩'>";echo "</from>";

 

上一篇:php教程--案例4(判断闰年)
下一篇:php教程--案例2

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2025年04月25日 04时55分34秒