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)); php能否实现局域网内文件搜索功能??? 很悲痛的一个问题 数组的键名 长度有限制吗? 请教:怎样做如vb的标签控件? 求一类 或说大概意思就行 谢谢 字符串截取 apache一段时间后,mysql无法连接 远程文件的问题~~100分 fopen打不开https的url吧? 请指点,php数组问题。 安装xampp遇到的问题 关于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));