Blogger Information
Blog 4
fans 0
comment 0
visits 1629
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php编程0805作业
沙漠狂奔的鱼
Original
458 people have browsed it

作业一

  1. <?php
  2. // 方法
  3. $arr=[23,3,45,6,78,8,34,88,23,55];
  4. $newarr=[];
  5. foreach($arr as $key=>$value){
  6. if($key%2==0){
  7. array_push($newarr,$arr[$key]);
  8. }
  9. }
  10. var_dump($newarr);
  11. //封装函数
  12. function getNewArrayByEeven($arr){
  13. $newarr=[];
  14. foreach($arr as $key=>$value){
  15. if($key%2==0){
  16. array_push($newarr,$arr[$key]);
  17. }
  18. }
  19. return $newarr;
  20. }
  21. var_dump(getNewArrayByEeven($arr));
  22. ?>

作业二

  1. <html >
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>简单的计算器</title>
  5. </head>
  6. <body>
  7. <form method="post" action="">
  8. 数1:<input type="text", name="n1" />+
  9. 数2:<input type="text", name="n2" />=
  10. <input type="submit" name="sub1" value="计算加法" />
  11. <p>
  12. <?php //这段是加法代码段
  13. if(isset($_POST['sub1']))//这是一个点击事件,当点击了sub1时候,执行下面的代码
  14. {
  15. $sub1=$_POST['n1']+$_POST['n2'];//获取将前面的两个框的值,相加赋值给$sub1;
  16. echo $_POST['n1'].'+'.$_POST['n2'].'='.$sub1;//输出结果
  17. }
  18. ?>
  19. <p>
  20. <form method="post" action="">
  21. 数1:<input type="text" name="n3" />-
  22. 数2:<input type="text" name="n4" />=
  23. <input type="submit" name="sub2" value="计算减法" />
  24. <p>
  25. <?php //这段是减法代码段
  26. if(isset($_POST['sub2']))
  27. //点击事件
  28. {
  29. $sub2=$_POST['n3']-$_POST['n4'];//获取相应的值
  30. echo $_POST['n3'].'-'.$_POST['n4'].'='.$sub2;
  31. }
  32. ?>
  33. <p>
  34. <form method="post" action="">
  35. 数1:<input type="text" name="n5" />*
  36. 数2:<input type="text" name="n6" />=
  37. <input type="submit" name="sub3" value="计算乘法" />
  38. <p>
  39. <?php //这是乘法的代码段
  40. if(isset($_POST['sub3'])){
  41. $sub3=$_POST['n5']*$_POST['n6'];
  42. echo $_POST['n5'].'*'.$_POST['n6'].'='.$sub3;
  43. }
  44. ?>
  45. <p>
  46. <form method="post" action="">
  47. 数1:<input type="text" name="n7" />/
  48. 数2:<input type="text" name="n8" />=
  49. <input type="submit" name="sub4" value="计算除法" />
  50. <p>
  51. <?php //这是除法代码段
  52. if(isset($_POST['sub4'] )){
  53. $sub4=$_POST['n7']/$_POST['n8'];
  54. echo $_POST['n7'].'/'.$_POST['n8'].'='.$sub4;
  55. }
  56. ?>
Correcting teacher:灭绝师太灭绝师太

Correction status:qualified

Teacher's comments:计算器作业可以更简单,参考我发到群里的0806预习资料 1-cal.php脚本
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post