Blogger Information
Blog 53
fans 3
comment 0
visits 55274
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
11月15日GET传值-***线上九期班
邯郸易住宋至刚
Original
507 people have browsed it

一、练习GET传值

代码如下

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>get</title>
  6. </head>
  7. <body>
  8. <form action="" method="get">
  9. <label for="email">邮箱:</label>
  10. <input type="email" id="email" name="email" value="">
  11. <label for="password">密码:</label>
  12. <input type="password" id="password" name="password" value="">
  13. <br/>
  14. <!--将用户输入的内容动态添加到value字段中, 创建具有粘性的表单-->
  15. <label for="email">邮箱:</label>
  16. <input type="email" id="email" name="email" value="<?php echo isset($_GET['email']) ? $_GET['email'] : ''; ?>">
  17. <label for="password">密码:</label>
  18. <input type="password" id="password" name="password" value="<?php echo isset($_GET['password']) ? $_GET['password'] : '';?>">
  19. <br/>
  20. <!--简易写法-->
  21. <label for="email">邮箱:</label>
  22. <input type="email" id="email" name="email" value="<?php echo $_GET['email'] ?? ''; ?>">
  23. <label for="password">密码:</label>
  24. <input type="password" id="password" name="password" value="<?php echo $_GET['password'] ?? ''; ?>">
  25. <button>登录</button>
  26. </form>
  27. </body>
  28. </html>
  29. <?php
  30. // 获取通过url发送的变量参数, php通过超全局变量$_GET获取
  31. // $_GET是一个数组,键名就是get参数名
  32. // 键名=>变量名, 值=>变量值
  33. // print_r()格式化打印输出一个数组
  34. print_r($_GET);
  35. echo $_GET['email'];
  36. // 获取变量之前要进行判断,用isset()
  37. if (isset($_GET['email'])) {
  38. echo $_GET['email'];
  39. } else {
  40. // 给个默认值
  41. $_GET['email'] = '';
  42. }
  43. // 与js类似,可以用三元运算符进行简化
  44. echo isset($_GET['email']) ? $_GET['email'] : '';
  45. // 使用<pre>标签,在网页中可以实现格式化输出
  46. echo '<pre>';
  47. print_r($_GET);
  48. ?>

运行结果如下:

二、PHP流程控制

1、三元运算符

代码如下:

  1. $var = 100;
  2. var_dump( $var>=100 ? '买' : '不买' );

运行结果:

2、if语句

代码

  1. $var = 10000;
  2. if($var >= 10000){
  3. $var1 = '我要买台mac';
  4. echo $var1;
  5. }

运行结果

3、if else 语句

代码

  1. $var = 10000;
  2. if($var >= 20000){
  3. $var1 = '我要买台mac';
  4. echo $var1;
  5. }else{
  6. $var2 = '我要洗洗睡觉';
  7. echo $var2;
  8. }

运行结果

4、if elseif else语句

代码

  1. $var = 3000;
  2. if($var >= 10000){
  3. echo '我要买个iphone xs max';
  4. }else if($var >= 8000){
  5. echo '我要买个iphone xs';
  6. }else if($var >= 6000){
  7. echo '我要买个iphone xr';
  8. }else if($var >= 4000){
  9. echo '我只能买个小米手机';
  10. }else{
  11. echo '我洗洗睡了';
  12. }

运行结果

5、switch case default语句

代码

  1. $var = 10000;
  2. switch ($var) {
  3. case $var >= 10000:
  4. echo '我要买个iphone xs max';
  5. break;
  6. case $var >= 8000:
  7. echo '我要买个iphone xs';
  8. break;
  9. case $var >= 6000:
  10. echo '我要买个iphone xr';
  11. break;
  12. case $var >= 4000:
  13. echo '我只能买个小米手机';
  14. break;
  15. default:
  16. echo '我洗洗睡了';
  17. break;
  18. }

运行结果

三、计数循环

代码

  1. for( $int=1; $int<10; $int++){
  2. echo $int;
  3. echo '<hr>';
  4. }

结果

四、手抄代码:

Correcting teacher:查无此人查无此人

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