Retrieving Day Names in PHP

前端 未结 7 664
-上瘾入骨i
-上瘾入骨i 2021-01-11 15:44

I need to display to user a list of localized day names (like \'Monday\', \'Tuesday\', ...) in a form. I know ho to get day name of any date. But is there a particular and f

7条回答
  •  天命终不由人
    2021-01-11 16:18

    setlocale(LC_TIME, 'de_DE');
    
    $today = ( 86400 * (date("N")) );
    
    for( $i = 0; $i < 7; $i++ ) {
        $days[] = strftime('%A', time() - $today + ($i*86400));
    }
    
    print_r($days);
    

    Obviously can be optimised by not calling time() 7 times etc but that's the gist. It gives you the right language for the locale and keeps Sun-Sat order of the array in tact.

提交回复
热议问题