Correction status:qualified
Teacher's comments:还会看数据包, 不错
一.foreach与它的替代语法,输出数组内容
1)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>POST</title> <style> table tr th{ width:60px; background-color:lightsalmon; } table tr td{ text-align:center; } </style> </head> <body> <?php $number=[[11,22,33,44,55],[22,33,44,55,66],[33,44,55,66,77],[44,55,66,77,88],[55,66,77,88,99]]; ?> <table border="1px solid black" cellpadding="10" cellspacing="0"> <thead> <tr> <th>id</th> <th>1</th> <th>2</th> <th>3</th> <th>4</th> <th>5</th> </tr> </thead> <tbody> <?php foreach($number as $key=>$value){ ?> <tr> <td><?php echo ($key+1) ?></td> <td><?php echo $value['0']?></td> <td><?php echo $value['1']?></td> <td><?php echo $value['2']?></td> <td><?php echo $value['3']?></td> <td><?php echo $value['4']?></td> </tr> <?php } ?> </tbody> </table> </body> </html>
点击 "运行实例" 按钮查看在线实例
2)使用foreach替代语法,, 将大括号用冒号代替
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>POST</title> <style> table tr th{ width:60px; background-color:lightsalmon; } table tr td{ text-align:center; } </style> </head> <body> <?php $number=[[11,22,33,44,55],[22,33,44,55,66],[33,44,55,66,77],[44,55,66,77,88],[55,66,77,88,99]]; ?> <table border="1px solid black" cellpadding="10" cellspacing="0"> <thead> <tr> <th>id</th> <th>1</th> <th>2</th> <th>3</th> <th>4</th> <th>5</th> </tr> </thead> <tbody> <?php foreach($number as $key=>$value): ?> <tr> <td><?php echo ($key+1) ?></td> <td><?php echo $value['0']?></td> <td><?php echo $value['1']?></td> <td><?php echo $value['2']?></td> <td><?php echo $value['3']?></td> <td><?php echo $value['4']?></td> </tr> <?php endforeach ?> </tbody> </table> </body> </html>
点击 "运行实例" 按钮查看在线实例
二.GET/POST数据处理过程
1)get
实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>get</title> </head> <body> <form action="" method="get"> <label for="email">邮箱:</label> <input type="email" id="email" name="email" value="<?php echo isset($_GET['email'])?$_GET['email']:""; ?>"> <br> <label for="password">密码:</label> <input type="password" id="password" name="password" value="<?php echo isset($_GET['password'])?$_GET['password']:""; ?>"> <br> <button>登录</button> </form> </body> </html> <?php echo "<pre>"; print_r($_GET); ?>
点击 "运行实例" 按钮查看在线实例
我们查看下数据包
可以发现get请求参数以键值对的方式,附加到url地址上,以&符号分割
2)post
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>POST</title> </head> <body> <form action="" method="post"> <label for="email">邮箱:</label> <input type="email" id="email" name="email" value="<?php echo isset($_POST['email'])?$_POST['email']:""; ?>"> <br> <label for="password">密码:</label> <input type="password" id="password" name="password" value="<?php echo isset($_POST['password'])?$_POST['password']:""; ?>"> <br> <button>登录</button> </form> </body> </html> <?php echo "<pre>"; print_r($_POST); ?>
点击 "运行实例" 按钮查看在线实例
我们查看下数据包
可以看到请求的数据在header请求头中被发送出去, url地址看不到请求参数