我的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/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;