PHP数组问题,求助! php数组日期排序 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 foreach($array as $v){ $days[]=date("Ymd",strtotime($v['day'])); $ar[date("Ymd",strtotime($v['day']))]=$v;} $arr= range(min($days),max($days));$max = max($arr);foreach($arr as $v){ $d = $max-$v; if(isset($ar[$v])){ $tt[$v]['day']=$ar[$v]['day']; $tt[$v]['count']=$ar[$v]['count']; for($i=1;$i<=$d;$i++) $tt[$v]['day_'.$i]=(int)$ar[$v]['day_'.$i]; }else{ $tt[$v]['day']=date("Y-m-j",strtotime($v)); $tt[$v]['count']=0; for($i=1;$i<=$d;$i++) $tt[$v]['day_'.$i]=0; }}print_r(array_values($tt)); 修改了一下,这个应该可以了。注意php版本至少要5.3.0或以上才能用。foreach($array as $v){ $days[]=date("Ymd",strtotime($v['day'])); $ar[date("Ymd",strtotime($v['day']))]=$v;} $p = new DatePeriod( new DateTime(min($days)), new DateInterval('P1D'), new DateTime(max($days)));foreach ($p as $d) { $arr[] = $d->format('Ymd');}$arr[]=max($days);$c = count($arr);foreach($arr as $k=>$v){ $d = $c-$k-1; if(isset($ar[$v])){ $tt[$v]['day']=$ar[$v]['day']; $tt[$v]['count']=$ar[$v]['count']; for($i=1;$i<=$d;$i++) $tt[$v]['day_'.$i]=(int)$ar[$v]['day_'.$i]; }else{ $tt[$v]['day']=date("Y-m-j",strtotime($v)); $tt[$v]['count']=0; for($i=1;$i<=$d;$i++) $tt[$v]['day_'.$i]=0; }}print_r(array_values($tt)); class="${$index++%2?'alt':''} ${$index<=2?'first':''}" 是什么意思? 搞了很久没有成功~有人帮我调试一个采集程序吗 计算点击次数 php如何操作注册表 php发送问题 关于JS的问题(涉及到浏览器知识) 请教PHP如何获得上传文件的后缀名??? 页面不能及时刷新问题 php的一段代码,在windows 2000、 nanoweb 、mysql 环境中没有提交数据 另一个问题,急,在线等!会ORACLE+PHP的朋友进来看看! 关于session小问题 thinkphp导出excel,怎样把表格里的数据传递到后台?现在只差这一步了
$days[]=date("Ymd",strtotime($v['day']));
$ar[date("Ymd",strtotime($v['day']))]=$v;
}
$arr= range(min($days),max($days));
$max = max($arr);
foreach($arr as $v){
$d = $max-$v;
if(isset($ar[$v])){
$tt[$v]['day']=$ar[$v]['day'];
$tt[$v]['count']=$ar[$v]['count'];
for($i=1;$i<=$d;$i++) $tt[$v]['day_'.$i]=(int)$ar[$v]['day_'.$i];
}else{
$tt[$v]['day']=date("Y-m-j",strtotime($v));
$tt[$v]['count']=0;
for($i=1;$i<=$d;$i++) $tt[$v]['day_'.$i]=0;
}
}
print_r(array_values($tt));
foreach($array as $v){
$days[]=date("Ymd",strtotime($v['day']));
$ar[date("Ymd",strtotime($v['day']))]=$v;
} $p = new DatePeriod(
new DateTime(min($days)),
new DateInterval('P1D'),
new DateTime(max($days))
);
foreach ($p as $d) {
$arr[] = $d->format('Ymd');
}
$arr[]=max($days);$c = count($arr);
foreach($arr as $k=>$v){
$d = $c-$k-1;
if(isset($ar[$v])){
$tt[$v]['day']=$ar[$v]['day'];
$tt[$v]['count']=$ar[$v]['count'];
for($i=1;$i<=$d;$i++) $tt[$v]['day_'.$i]=(int)$ar[$v]['day_'.$i];
}else{
$tt[$v]['day']=date("Y-m-j",strtotime($v));
$tt[$v]['count']=0;
for($i=1;$i<=$d;$i++) $tt[$v]['day_'.$i]=0;
}
}
print_r(array_values($tt));