1. 创建一个数组,使用foreach与它的替代语法,在html中输出数组内容;
2. 创建一个表单, 演示get和post的数据处理过程
实例
<?php
$array1=["aaa",123,"你我他"];
foreach ($array1 as $key=>$value){
echo ($key+1).'.'.$value.'<br>';
};
foreach ($array1 as $key=>$value) :
echo ($key+1).'.'.$value.'<br>';
endforeach;
Echo "<hr>"
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="" method="get">
<label for="username">用户名:</label>
<input type="username" name="username" id="username" value="<?php echo isset($_GET['username'])?$_GET['username']:"请输入用户名"; ?>">
<label for="password">密码:</label>
<input type="password" name="password" id="password" value="">
<button>登陆</button>
</form>
<?php
print_r($_GET);
echo '<br>';
echo $_GET['username'];
echo '<br>';
var_dump(isset($_GET['username']));
echo '<br>';
//if (isset($_GET['username'])){
// echo $_GET['username'];
//}else{
// echo "请输入用户名";
//}
echo isset($_GET['username'])?$_GET['username']:"请输入用户名";
?>
</body>
</html>
运行实例 »点击 "运行实例" 按钮查看在线实例
Correction status:qualified
Teacher's comments:在纯php代码,没有必要使用替代语法,应该用在html+php混写的时候:
<?php
$array1=["aaa",123,"你我他"];
foreach ($array1 as $key=>$value){
echo ($key+1).'.'.$value.'<br>';
};
foreach ($array1 as $key=>$value) :
echo ($key+1).'.'.$value.'&
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!