实例
<?php //定义一个数组用于foreach遍历 $arr = ["中国","美国","英国","法国","俄罗斯"]; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>使用foreach与它的替代语法,在html中输出数组内容;演示get和post的数据处理过程t</title> </head> <body> <h5>foreach遍历数组演示</h5> <ul> <?php foreach ($arr as $value): ?> <li><?php echo $value; ?></li> <?php endforeach; ?> </ul> <hr> <h5>GET请求演示</h5> <form action="" method="GET" > <p> 邮箱: <input type="text" name="email" value=""> </p> <p> 密码: <input type="password" name="password" value=""> </p> <p> <button>提交</button> </p> </form> <?php $val1 = $_GET["email"]; $val2 = $_GET["password"]; echo $val1 ?? '邮箱为空'; echo "</br>"; echo $val2 ?? '密码为空'; ?> <hr> <h5>POST请求演示</h5> <form action="" method="post" > <p> 邮箱: <input type="text" name="email1" value=""> </p> <p> 密码: <input type="password" name="password1" value=""> </p> <p> <button>提交</button> </p> </form> <?php $val3 = $_POST["email1"]; $val4 = $_POST["password1"]; echo $val3 ?? '邮箱为空'; echo "</br>"; echo $val4 ?? '密码为空'; ?> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例