• PHP基本语法练习题


    输入10个人的姓名成绩,按从大到小排序打印出来

     1 <?php
     2 ?>
     3 <form action="" method="post">
     4 姓名:<input type="text" name="xm1"  style="50px; height:20px;"/>
     5 成绩:<input type="text" name="cj1"  style="50px; height:20px;"/><br />
     6 姓名:<input type="text" name="xm2"  style="50px; height:20px;"/>
     7 成绩:<input type="text" name="cj2"  style="50px; height:20px;"/><br />
     8 姓名:<input type="text" name="xm3"  style="50px; height:20px;"/>
     9 成绩:<input type="text" name="cj3"  style="50px; height:20px;"/><br />
    10 姓名:<input type="text" name="xm4"  style="50px; height:20px;"/>
    11 成绩:<input type="text" name="cj4"  style="50px; height:20px;"/><br />
    12 姓名:<input type="text" name="xm5"  style="50px; height:20px;"/>
    13 成绩:<input type="text" name="cj5"  style="50px; height:20px;"/><br />
    14 姓名:<input type="text" name="xm6"  style="50px; height:20px;"/>
    15 成绩:<input type="text" name="cj6"  style="50px; height:20px;"/><br />
    16 姓名:<input type="text" name="xm7"  style="50px; height:20px;"/>
    17 成绩:<input type="text" name="cj7"  style="50px; height:20px;"/><br />
    18 姓名:<input type="text" name="xm8"  style="50px; height:20px;"/>
    19 成绩:<input type="text" name="cj8"  style="50px; height:20px;"/><br />
    20 姓名:<input type="text" name="xm9"  style="50px; height:20px;"/>
    21 成绩:<input type="text" name="cj9"  style="50px; height:20px;"/><br />
    22 姓名:<input type="text" name="xm10"  style="50px; height:20px;"/>
    23 成绩:<input type="text" name="cj10"  style="50px; height:20px;"/><br />
    24 
    25 <input type="submit" value="点击排序" />
    26 </form>
    27 <?
    28      //定义数组cj,接收文本框里的成绩;
    29      $cj[0]=$_POST['cj1'];
    30      $cj[1]=$_POST['cj2'];
    31      $cj[2]=$_POST['cj3'];
    32      $cj[3]=$_POST['cj4'];
    33      $cj[4]=$_POST['cj5'];
    34      $cj[5]=$_POST['cj6'];
    35      $cj[6]=$_POST['cj7'];
    36      $cj[7]=$_POST['cj8'];
    37      $cj[8]=$_POST['cj9'];
    38      $cj[9]=$_POST['cj10'];
    39      //定义数组xm,接收文本框里的姓名;
    40      $xm[0]=$_POST['xm1'];
    41      $xm[1]=$_POST['xm2'];
    42      $xm[2]=$_POST['xm3'];
    43      $xm[3]=$_POST['xm4'];
    44      $xm[4]=$_POST['xm5'];
    45      $xm[5]=$_POST['xm6'];
    46      $xm[6]=$_POST['xm7'];
    47      $xm[7]=$_POST['xm8'];
    48      $xm[8]=$_POST['xm9'];
    49      $xm[9]=$_POST['xm10'];
    50      //定义中间变量,进行冒泡排序;
    51      $zhong;
    52      for($i=0;$i<10;$i++)
    53      {
    54          for($j=$i;$j<9;$j++)
    55          {
    56              if($cj[$i]<$cj[$j+1])
    57              {
    58                  $zhong=$cj[$j+1];
    59                  $cj[$j+1]=$cj[$i];
    60                  $cj[$i]=$zhong;
    61              }
    62          }
    63      }
    64      //遍历数组,输出姓名和成绩;
    65      for($k=0;$k<count($cj);$k++)
    66      {
    67          echo"$xm[$k] ";
    68          echo"$cj[$k]<br>";
    69      }
    70 ?>
  • 相关阅读:
    ASP.NET MVC5(二):控制器、视图与模型
    LINUX重启MYSQL的命令
    mysql unrecognized service问题解决
    UML类图几种关系的总结
    java用org.apache.poi包操作excel
    struts2.xml 中result type属性说明
    MySql Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 解决方法
    报错:1130-host ... is not allowed to connect to this MySql server 开放mysql远程连接 不使用localhost
    linux下使用yum安装mysql
    关于LINUX权限-bash: ./startup.sh: Permission denied
  • 原文地址:https://www.cnblogs.com/Itwonderful/p/5390643.html
Copyright © 2020-2023  润新知