PHP 7.0 mktime not working

前端 未结 3 627
失恋的感觉
失恋的感觉 2021-01-21 22:40

getting months using mktime not working in PHP 7.0.

    $month_options=\"\";
    for( $i = 1; $i <= 12; $i++ ) {
        $month_num = str_pad( $i, 2, 0, STR_P         


        
3条回答
  •  梦谈多话
    2021-01-21 23:05

    Why not use DateTime objects instead? They are easier to work with, and easier to manipulate. DateTime is available from PHP5.2 and upwards.

    This snippet

    $date = new DateTime("january");
    for ($i = 1; $i <= 12; $i++) {
        echo $date->format("F")."\n";
        $date->modify("+1 months");
    }
    

    would output

    January
    February
    March
    April
    May
    June
    July
    August
    September
    October
    November
    December
    

    Live demo

提交回复
热议问题