Blogger Information
Blog 6
fans 0
comment 0
visits 2460
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
3.19作业
小5的博客
Original
507 people have browsed it
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
 table{border: 1px solid #ccc;text-align: center;margin: 0 auto;}
        td{height: 30px;width: 150px}
        h1{text-align: center}
    </style>

 <?php
 $a = '学成***';
 $array_1 = array(
        ['id' => 1 ,'name' => '张三' ,'sex' => 1 ,'num' => 20 ,'add' => '玉溪市'],
 ['id' => 2 ,'name' => '张四' ,'sex' => 0 ,'num' => 90 ,'add' => '玉溪市'],
 ['id' => 3 ,'name' => '张五' ,'sex' => 1 ,'num' => 77 ,'add' => '玉溪市'],
 );
 function creatArray($array_1){
 $result = '';//定义一个空变量用来存放遍历数组后的每一个值
 foreach ($array_1 as $value){
 $result .= '<tr>';
 $result .= '<td>'.$value['id'].'</td>';
 $result .= '<td>'.$value['name'].'</td>';
 $result .= '<td>'.($value['sex'] ? '男':'女').'</td>'; //判断性别 1为男 0为女
 $result .= '<td>'.($value['num'] >= 60 ? '成绩合格' : '成绩不合格').'</td>'; //判断是否及格 >=60及格
 $result .= '<td>'.$value['add'].'</td>';
 $result .= '</tr>';
 //所有的result组合成一个<tr><td></td></tr>表格,有多个数组就组合成多个数组
 }return $result; //每遍历一个就输出一个
 }
 ?>

</head>
<body>
 <?php echo '<h1>'.$a.'</h1>';?>
 <table>
        <tr>
            <td>编号</td>
            <td>姓名</td>
            <td>性别</td>
            <td>成绩</td>
            <td>地址</td>
        </tr>
 <!--调用 creatArray()自定义函数 实现:输出学员信息-->
 <?php echo creatArray($array_1) ?>
 </table>
</body>
</html>


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