如何使用PHP获取每个月的第一天数组值
日期数据返回我的数组。我想每个月日期一个数组集如何使用PHP获取每个月的第一天数组值,php,Php,日期数据返回我的数组。我想每个月日期一个数组集 Array ( [2014/09/01 13:47:54] => 73206 [2014/09/02 11:00:01] => 73205 [2014/10/01 14:00:07] => 73206 [2014/10/03 15:00:01] => 73207 [2014/11/01 18:00:02] => 73208 [2014/11/05 02:00:01] =&
Array
(
[2014/09/01 13:47:54] => 73206
[2014/09/02 11:00:01] => 73205
[2014/10/01 14:00:07] => 73206
[2014/10/03 15:00:01] => 73207
[2014/11/01 18:00:02] => 73208
[2014/11/05 02:00:01] => 73209
[2014/12/01 10:00:01] => 73210
[2014/12/02 12:00:02] => 73209
[2014/12/04 13:00:02] => 73208
[2014/01/01 23:00:02] => 73209
[2014/01/08 09:00:02] => 73210
[2014/02/01 10:00:03] => 73211
[2014/02/19 11:00:02] => 73210
)
我的期望是这样的
[2014/09/01 13:47:54] => 73206
[2014/10/01 14:00:07] => 73206
[2014/11/01 18:00:02] => 73208
[2014/12/01 10:00:01] => 73210
[2014/01/01 23:00:02] => 73209
[2014/02/01 10:00:03] => 73211
你的回答
请你详细说明一下,你面临的问题是什么?你能解释一下你尝试过的事情吗?你想让17,18 19这样每个月第一个数组值必须知道如何使用php。@Saravana Kumar试试这个…谢谢你的帮助,但是我的期望[2014/09/01 13:47:54]=>73206[2014/10/01 14:00:07]=>73206[2014/11/01 18:00:02]=>73208[2014/12/01 10:00:01]=>73210[2014/01/01 23:00:02]=>73209[2014/02/01 10:00:03]=>73211请指导我如何获得我正在提交您的答案
try this
<?php
$data=Array ( "2014-09-17 13:47:54" => "73206", "2014-09-17 11:00:01" => "73205",
"2014-10-17 14:00:07" => "73206",
"2014-10-17 15:00:01" => "73207",
"2014-11-17 18:00:02" => "73208",
"2014-11-18 02:00:01" => "73209",
"2014-12-18 10:00:01" => "73210",
"2014-12-18 12:00:02" => "73209",
"2014-12-18 13:00:02" => "73208",
"2014-01-18 23:00:02" => "73209",
"2014-01-19 09:00:02" => "73210",
"2014-02-19 10:00:03" => "73211", "2014-02-19 11:00:02" => "73210" );
echo '<pre>';
print_r($data);
foreach ($data as $key => $value) {
$getdate=date('d',strtotime($key));
$getmonth=date('M',strtotime($key));
echo 'Date=>'.$getdate.' Month=>'.$getmonth;
//echo $getdate=date('d-m-y',strtotime(''));
echo '<br>';
}
?>
<?php
$data=Array ( "2014/09/01 13:47:54" => "73206", "2014/09/02 11:00:01" => "73205",
"2014/10/01 14:00:07" => "73206",
"2014/10/17 15:00:01" => "73207",
"2014/10/03 15:00:01" => "73208",
"2014/11/01 18:00:02" => "73209",
"2014/11/05 02:00:01" => "73210",
"2014/12/01 10:00:01" => "73209",
"2014/12/18 13:00:02" => "73208",
"2014/12/02 12:00:02" => "73209",
"2014/12/04 13:00:02" => "73210",
"2014/01/01 23:00:02" => "73211", "2014/01/08 09:00:02" => "73210" );
echo '<pre>';
print_r($data);
foreach ($data as $key => $value) {
$getdate=date('d',strtotime($key));
if($getdate=='01' || $getdate=='1'){
echo '['.$key.']'.'=>'.$value;
}
echo '<br>';
}
?>