日期:2014-05-16 浏览次数:20495 次
$ar = array(Array
'2014-01-01',
'2014-01-02',
'2014-01-22',
'2014-02-22',
'2014-02-26',
'2014-03-03',
'2014-03-25',
'2014-03-28',
);
$r1 = $r2 = array();
foreach($ar as $d) {
list($y, $m, $d) = explode('-', $d);
if(! isset($r1[$y.$m])) $r1[$y.$m] = 32;
$r1[$y.$m] = min($r1[$y.$m], $d);
if(! isset($r2[$y.$m])) $r2[$y.$m] = 0;
$r2[$y.$m]++;
}
print_r($r1);
print_r($r2);
$arr = array('2014-01-01','2014-01-02','2014-01-22','2014-02-22','2014-02-26','2014-03-03','2014-03-25','2014-03-28');
sort($arr);
$out = array();
foreach ($arr as $key => $value) {
$mouth = date('n',strtotime($value));
if(!in_array($mouth, array_keys($out))) $out[$mouth] = $value;
}
var_dump($out);
$arr = array('2014-01-01','2014-01-02','2014-01-22','2014-02-22','2014-02-26','2014-03-03','2014-03-25','2014-03-28');
$newArr = array_map('cout', $arr);
function cout($n){
return date('n',strtotime($n));
}
print_r ( array_count_values ( $newArr ));
<?php
$months = array('2014-01-01','2014-01-02','2014-01-22','2014-02-22','2014-02-26','2014-03-03','2014-03-25','2014-03-28');
month_min_day($months);
month_days($months);
function month_min_day($months){
$tmp = array();
foreach($months as $month){
$key = date('Y-m',strtotime($month));
if(!isset($tmp[$key])
------解决方案--------------------
strtotime($month)<$tmp[$key]){
$tmp[$key] = strtotime($month);
}
}
foreach($tmp as $key=>$val){
echo date('Y-m-d',$val).'<br>';
}
}
function month_days($months){
$tmp = array();
&nbs