Blogger Information
Blog 28
fans 0
comment 0
visits 15749
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0805作业 找出数组偶数 和 计算器
︷肉園耔︷
Original
674 people have browsed it

—图例

  1. <?php
  2. /*循环
  3. for foreach while do ..while
  4. */
  5. $cities = ['合肥','南京','苏州','上海','杭州','东莞'];
  6. /*echo current($cities);
  7. next ($cities);
  8. echo current($cities);
  9. next($cities);
  10. echo current($cities);*/
  11. while ( $city=current($cities)):
  12. echo current($cities).'<br>';
  13. //前移针针
  14. next($cities);
  15. endwhile;
  16. //var_dump(current($cities));
  17. reset($cities);
  18. var_dump($cities);
  19. var_dump(count($cities));
  20. //do .. while出口循环
  21. $i=0;
  22. do{
  23. echo $cities[$i];
  24. $i++;
  25. }while($i<count($cities));
  26. echo '<hr>';
  27. //for计算循环 for(初始条件;循环条件;更新条件){满足循环条件所执行的代码块}
  28. for ($i=0;$i<count($cities);$i++){
  29. //break提前结束循环
  30. if($i == 2 ) continue;
  31. echo $cities[$i],'<br>';
  32. }
  33. ob_clean();
  34. /*
  35. * foreach 用于遍历数组
  36. * foreach($array as $value){
  37. * 处理数组成员 $value}
  38. */
  39. $cities = ['合肥','南京','苏州','上海','杭州','东莞'];
  40. foreach($cities as $vlues ) {
  41. echo "<h1 style='color:pink'><center>$vlues</center></h1>";
  42. };
  43. $info=[['create_time'=>1321657471,'name'=>'peter'],
  44. ['create_time'=>1321341451,'name'=>'chloe'],
  45. ['create_time'=>1322312471,'name'=>'mile']];
  46. foreach($info as $k =>$v){
  47. $info[$k]['create_time']=date("Y-m-d H:m:s",$v['create_time']);
  48. }
  49. echo '<pre>';
  50. print_r($info);
  51. $info1=[
  52. ['贵州'=>'贵阳'],
  53. ['贵州'=>'遵义'],
  54. ['贵州'=>'安顺']];
  55. foreach($info as $k=>$value){
  56. ;
  57. }
  58. print_r($info1);
  59. //作业1 $arr = [23,3,45,6,78,8,34],
  60. $arr = [23,3,45,6,78,8,34];
  61. for($i=0;$i<count($arr);$i++){
  62. if(($arr[$i])%2==0){
  63. $a= "$arr[$i]".',';}
  64. }

—- 计算机器

— 图例


—- 代码区

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <title>Document</title>
  9. </head>
  10. <body>
  11. <form method="post">
  12. <input type="text" name="first" />
  13. <select name="s" id="">
  14. <option value="+">+</option>
  15. <option value="-">-</option>
  16. <option value="*">*</option>
  17. <option value="%">%</option>
  18. <option value="/">/</option>
  19. </select>
  20. <input type="text" name="second">
  21. <input type="submit" value="结果">
  22. </form>
  23. </body>
  24. </html>
  25. <?php
  26. //判断是否PHP的得到值
  27. $first=$_POST["first"]; //获得name为first的值
  28. $v=$_POST["s"]; //获取name为s的值
  29. $second=$_POST["second"]; //获取name为second的值
  30. if($v=="+"){
  31. echo $first."+".$second."结果为".($first+$second);
  32. }elseif($v== "-"){
  33. echo $first."-".$second."结果为".($first-$second);
  34. }elseif($v== "*"){
  35. echo $first."*".$second."结果为".($first-$second);
  36. }elseif($v=="/"){
  37. if($second ==0){
  38. echo "除数不能为0";
  39. }else{
  40. echo $first."/".$second."结果为".($first/$second);
  41. }
  42. }elseif($v == "%"){
  43. if($second ==0){
  44. echo "除数不能为0";
  45. }else{
  46. echo $first."%".$second."结果为".($first%$second);
  47. }
  48. }
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
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