控制器
$arr=array(
array('name'=>'王','yuwen'=>75,'shuxue'=>80,'yingyu'=>110,'datetime'=>'201702'),
array('name'=>'李','yuwen'=>85,'shuxue'=>60,'yingyu'=>90,'datetime'=>'201701'),
array('name'=>'张','yuwen'=>95,'shuxue'=>83,'yingyu'=>70,'datetime'=>'201701'),
array('name'=>'周','yuwen'=>77,'shuxue'=>95,'yingyu'=>40,'datetime'=>'201701'),
array('name'=>'吴','yuwen'=>82,'shuxue'=>96,'yingyu'=>55,'datetime'=>'201701'),
array('name'=>'王','yuwen'=>79,'shuxue'=>80,'yingyu'=>96,'datetime'=>'201701'),
array('name'=>'李','yuwen'=>84,'shuxue'=>105,'yingyu'=>80,'datetime'=>'201702'),
array('name'=>'张','yuwen'=>95,'shuxue'=>66,'yingyu'=>117,'datetime'=>'201702'),
array('name'=>'周','yuwen'=>101,'shuxue'=>77,'yingyu'=>108,'datetime'=>'201702'),
array('name'=>'吴','yuwen'=>115,'shuxue'=>55,'yingyu'=>60,'datetime'=>'201702'),
);
/*格式:array(
'王'=>array(
'201701'=>array('yuwen'=>75,''),
'201702'=>array(),
)
);*/
//提出所有的时间并按升序排序(不重复)
$time=array_unique(array_column($arr, 'datetime'));
sort($time);
$data=array();
foreach ($arr as $v){
$data[$v['name']][$v['datetime']]=$v;
}
//按照时间排序
foreach ($data as $k=>$v){
ksort($data[$k]);
}
$this->assign('time',$time);
$this->assign('data',$data);
$this->display();
}
模式格式
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
td{width:100px;text-align:center}
</style>
</head>
<body>
<table border="1" cellspacing="0" cellpadding="0">
<caption>成绩表</caption>
<tr>
<td rowspan="2">姓名</td>
<foreach name="time" item="vo">
<td colspan="3" align="center">{$vo}</td>
</foreach>
</tr>
<tr>
<foreach name="time" item="vo">
<td>语文</td>
<td>数学</td>
<td>英语</td>
</foreach>
</tr>
<foreach name="data" item="vo" key="k">
<tr>
<td>{$k}</td>
<foreach name="vo" item="vs">
<td>{$vs.yuwen}</td>
<td>{$vs.shuxue}</td>
<td>{$vs.yingyu}</td>
</foreach>
</tr>
</foreach>
</table>
</body>
</html>
显示结果:
QQ截图20170629144503.png
网友评论