PHP迭代结果并按日期过滤
我有如下json结果PHP迭代结果并按日期过滤,php,Php,我有如下json结果 { "status": 200, "success": true, "data": [ "Reports/2017/04/01/name.csv", "Reports/2017/05/16/name.csv", "Reports/2017/05/19/name.csv", "Reports/2017/06/20/name.csv", "Reports/2017/07/23/name.csv", "Reports/2017/07/26
{
"status": 200,
"success": true,
"data": [
"Reports/2017/04/01/name.csv",
"Reports/2017/05/16/name.csv",
"Reports/2017/05/19/name.csv",
"Reports/2017/06/20/name.csv",
"Reports/2017/07/23/name.csv",
"Reports/2017/07/26/name.csv",
"Reports/2017/09/27/name.csv"
],
"message": "Success"
}
这些是我的API结果,我有一个类型(每周或每月)变量。因此,当我每月传递类型值时,我的结果应该是
"Reports/2017/04/01/name.csv",
"Reports/2017/05/19/name.csv",
"Reports/2017/06/20/name.csv",
"Reports/2017/07/26/name.csv",
"Reports/2017/09/27/name.csv"
我想要那个月的最新csv文件,我不想要那个月的所有csv值。有谁能建议我如何让它工作
下面是我的代码
//comparing two dates and passing the dates for S3 bucket and i am saving all those values in array
$begin = new DateTime("2017-01-17");
$end = new DateTime("2017-09-28");
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($begin, $interval, $end);
$date = "2017-01-17";
$type = "month" // now my type is month, so i want to get the latest entry of csv file for each month
$all_objs = array();
foreach ( $period as $dt )
{
$res_objs = $client->getIterator('ListObjects', array(
"Bucket" => $bucket,
"Prefix" => 'Reports/'.$date.'/name.csv'
));
//$res_objs stores all the csv files from csv
foreach ($res_objs as $obj) {
// here i am saving in array
array_push($all_objs, $obj['Key']);
}
$date = date ("Y/m/d", strtotime("+1 day", strtotime($date)));
}
// now, here i want to save those latest entries in a variable.
return $all_objs;
什么意思-
最新的
?是的,我想获得每个月的最新csv文件。请使用迭代每个
,商店查找-月=>天请发布您当前的代码