php 判断月份中最小的日期 php 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $ar = 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);Array( [201401] => 01 [201402] => 22 [201403] => 03)Array( [201401] => 3 [201402] => 2 [201403] => 3) 1.$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);2.$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 )); 比较简单$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');$data = array();foreach($arr as $_arr){ list($y, $m, $d) = explode('-', $d); $data[$m] = isset($data[$m]) ? ($data[$m]>$d ? $d : $data[$m]) : $d;} 如果要考虑不同年相同月份的情况,例如2014-02 与 2013-02 需要分开统计。key的值要用Y-m格式。<?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(); foreach($months as $month){ $key = date('Y-m',strtotime($month)); isset($tmp[$key])? $tmp[$key]++ : $tmp[$key]=1; } foreach($tmp as $key=>$val){ echo $key.'->'.$val.'<br>'; }}?> php 如何取Array值。 php网站自动安装是如何实现的?? dedecms关键字替换连接 使用PHP如何获得JS生成的年和月? 谁帮我看看哪里错了,Parse error: parse error, unexpected $end ,谢谢啊!!! 新手问个简单的问题 gd库的问题. 如何动态显示时间(倒计时),并可以更新页面内容?高手们过来看看 急,一个有关cookie的问题 求帮解密一个很有难度的php混淆加密文件,在线等 php 如何跟踪谁订阅了我的RSS? 怎么用js 传递参数 到php文件
'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);
Array
(
[201401] => 01
[201402] => 22
[201403] => 03
)
Array
(
[201401] => 3
[201402] => 2
[201403] => 3
)
$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);
2.
$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 ));
$data = array();
foreach($arr as $_arr){
list($y, $m, $d) = explode('-', $d);
$data[$m] = isset($data[$m]) ? ($data[$m]>$d ? $d : $data[$m]) : $d;
}
<?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();
foreach($months as $month){
$key = date('Y-m',strtotime($month));
isset($tmp[$key])? $tmp[$key]++ : $tmp[$key]=1;
}
foreach($tmp as $key=>$val){
echo $key.'->'.$val.'<br>';
}
}
?>