$name="yAngrUilIn";

$age=18;

$motto=“人最重要的就是要relax!”;

利用foreach进行简单的练习题:模拟取出数组中的数据并导入html建立用户信息表;

 

//建立数组

<?php

$userlist[]=['id'=>1,'username'=>'yang','age'=>18,'department'=>'器械区','monthlypay'=>15475.00];

$userlist[]=['id'=>2,'username'=>'zhang','age'=>31,'department'=>'游泳区','monthlypay'=>8740.00];

$userlist[]=['id'=>3,'username'=>'wang','age'=>25,'department'=>'拳馆','monthlypay'=>4570.00];

$userlist[]=['id'=>4,'username'=>'leng','age'=>17,'department'=>'瑜伽区','monthlypay'=>15475.00];

 

?>

//html部分

<!DOCTYPE html>

<html>

  <head>

    <meta charset="utf-8" >

    <title>练习:用户信息表</title>

    <style>

      h1,table{

        text-align:center;

}

      table{

        margin: 0 auto;

}

    </style>

  </head>

  <body>

    <h1>用户信息表</h1>

    <table border="1" width="80%"  bgcolor="abcdef" cellpadding="0" cellspacing="0">

      <tr>

        <td>会员号</td>

        <td>用户名</td>

        <td>年龄</td>

        <td>训练区域</td>

        <td>月薪</td>

      </tr>

//遍历数组,取出数据,插入数据。

      <?php

        foreach($userlist as $value){

      ?>

          <tr>

            <td><?php echo $value['id']; ?></td>

            <td><?php echo $value['username']; ?></td>

            <td><?php echo $value['age']; ?></td>

            <td><?php echo $value['department']; ?></td>

            <td><?php echo $value['monthlypay']; ?></td>

          </tr>

      <?php

      }

      ?>

    </table>

  </body>

</html>

age