控制器
$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();
}
模式格式
Insert title here
成绩表
姓名 |
{$vo} |
语文 |
数学 |
英语 |
{$k} |
{$vs.yuwen} |
{$vs.shuxue} |
{$vs.yingyu} |
显示结果: