批改状态:未批改
老师批语:
<?php
header('Content-type: text/html; charset=utf-8');
$arr = array(
array( 1, '王大大', 30, 1, 123456),
array( 2, '张三', 18, 2, 123456),
array( 3, '李四',16, 1, 123456),
array( 4, '欧阳克',20, 2, 123456),
);
//求数量;
$like=count($arr);
//定义一个标题的名称
$title='大人物';
function createtable($arr){
$str= '';
//将这个数组进行循环;
foreach ($arr as $value) {
$str .= '<tr>';
$str .= '<td>' . $value['0'] . '</td>';
$str .= '<td>' . $value['1'] . '</td>';
$str .= '<td>' . $value['2'] . '</td>';
$str .= '<td>' . ($value['3']==1?'男':'女') . '</td>';
$str .= '<td>' . $value['4'] . '</td>';
$str .= '</tr>';
}
//将结果$str返回(给createtable函数;)
return $str;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>php3月19直播作业</title>
<style type="text/css">
*{margin: 0;padding: 0;}
th,td{
border:1px solid blue;
padding: 8px;
}
table{
width: 60%;
margin: 30px auto;
text-align: center; /*文字居中;*/
border-collapse: collapse;
}
th{
background:red;
}
p {
/*margin-top: 20px;*/
text-align: center;
}
h2{
margin-top: 120px;
text-align: center;
}
</style>
</head>
<body>
<table>
<h2><?php echo $title;?></h2>
<tr>
<th>编号</th>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
<th>密码</th>
</tr>
<?php echo createtable($arr); ?>
</table>
<p>总人数: <?php echo $like;?>人</p>
</body>
</html>总结;
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号