一、创建一个数组,使用foreach与它的替代语法,在html中输出数组内容;
<?php
$array = ['首页','关于我们','公司新闻','图片列表','在线留言','联系我们']
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>1. 创建一个数组,使用foreach与它的替代语法,在html中输出数组内容;</title>
<style>
.nav{
width: 850px;
height: 60px;
background: #ccc;
margin: 0 auto;
padding: 0 20px;
}
.nav li{
width: 120px;
list-style: none;
float: left;
padding: 0 10px;
line-height: 60px;
text-align: center;
}
.nav li:hover{
background: #444444;
}
.nav li a{
color: white;
text-align: center;
text-decoration: none;
}
</style>
</head>
<body>
<div id="box">
<ul class="nav">
<?php foreach ($array as $key=>$value): ?>
<li><a href="#"><?php echo $array[$key] ?></a></li>
<?php endforeach; ?>
</ul>
</div>
</body>
</html>
二、创建一个表单, 演示get和post的数据处理过程
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>2. 创建一个表单, 演示get和post的数据处理过程</title>
</head>
<body>
<!-- 1.GET 请求-->
<?php
// if(isset($_GET['email'])){
// echo $_GET['email'];
// }else{
// echo '';
// } ;
echo isset($_GET['email']) ? $_GET['email'] :'';
?>
<form action=""method="get">
<p>
<label for="email">邮箱:</label>
<input type="text" name="email" id="email" value="<?php echo isset($_GET['email']) ? $_GET['email'] :''; ?>">
</p>
<p>
<label for="password">密码:</label>
<input type="text" name="password" id="password" value="<?php echo isset($_GET['password']) ? $_GET['password'] :''; ?>">
</p>
<p>
<button>提交</button>
</p>
</form>
<hr>
<!--2.POST请求-->
<form action=""method="post">
<p>
<label for="email">邮箱:</label>
<input type="text" name="email" id="email" value="<?= $_POST['email'] ?? '' ?>">
</p>
<p>
<label for="password">密码:</label>
<input type="text" name="password" id="password" value="<?= $_POST['password'] ?? '' ?>">
</p>
<p>
<button>提交</button>
</p>
</form>
</body>
</html>