Blogger Information
Blog 29
fans 0
comment 0
visits 19489
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
foreach与它的替代语法,输出数组内容,GET/POST数据处理过程-2019年7月22日
blog
Original
587 people have browsed it

一.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>

运行实例 »

点击 "运行实例" 按钮查看在线实例

1.png

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>

运行实例 »

点击 "运行实例" 按钮查看在线实例

1.png

二.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);
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例

1.png

我们查看下数据包

1.png

可以发现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);
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例

1.png

我们查看下数据包

1.png

可以看到请求的数据在header请求头中被发送出去, url地址看不到请求参数

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
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!