Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
printf("Current PHP version: %s \n", phpversion());
$arr = array(
"2020-08-09 11:22:33" => "2020-08-09 2021",
"2020-08-09 11:01:44" => "2020-08-09 2022",
"2020-08-09 11:36:21" => "2020-08-09 2023",
"2020-08-08 10:22:55" => "2020-08-09 2024",
"2020-08-08 07:22:28" => "2020-08-09 2025",
"2020-08-08 17:22:32" => "2020-08-09 2026",
"2020-08-07 18:52:45" => "2020-08-09 2027"
);
print_r($arr);
$dates_array = array();
foreach($arr as $key => $value)
{
$new_date = date("Y-m-d",strtotime($key));
$dates_array[] = $new_date;
}
$result = array_unique($dates_array);
print_r($dates_array); //to print array collection
print_r($result);
sort($result);
$retention_days = 1;
$new_result = array_slice($result,$retention_days);
print_r($new_result);
foreach($new_result as $val)
{
foreach($arr as $key => $value)
{
if(strpos($key , $val) !== false)
{
$new_array[$key][] = $value;
}
}
}
print_r($new_array);
//print_r($othr_array);