Get most recent date from an array of dates

后端 未结 11 689
小鲜肉
小鲜肉 2020-11-28 11:32

I have the array of dates below

array(5) { 
    [0]=> string(19) \"2012-06-11 08:30:49\" 
    [1]=> string(19) \"2012-06-07 08:03:54\" 
    [2]=> st         


        
11条回答
  •  Happy的楠姐
    2020-11-28 11:34

    Here is my suggestion:

    $most_recent = 0;
    
    foreach($array as $key => $date){
        if( strtotime($date) < strtotime('now') && strtotime($date) > strtotime($array[$most_recent]) ){
            $most_recent = $key;
        }
    }
    
    print $array[$most_recent]; //prints most recent day
    

提交回复
热议问题