Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
PHP 7.0 mktime not working

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_PAD_LEFT );
        $month_name = date( 'F', mktime( 0, 0, 0, $i + 1, 0, 0, 0 ));
        $selected="";
        $month_options.$month_name."<br/>";
    }
    echo $month_options;

Result in PHP 5.5

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

Result in 7.0

January
January
January
January
January
January
January
January
January
January
January

please help me how to reslove this issue?..thanks in advance

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

It is cleary written here that last parameter is_dst of mktime has been removed in PHP 7, You have to give 6 parameters instead of 7.

Try this code snippet here 7.0.8

<?php

ini_set('display_errors', 1);
$month_options = "";
for ($i = 1; $i <= 12; $i++)
{
    $month_num = str_pad($i, 2, 0, STR_PAD_LEFT);
    $month_name = date('F', mktime(0, 0, 0, $i + 1, 0, 0));
    $selected = "";
    $month_options .= $month_name . "<br/>";
}
echo $month_options;
about 4 years ago · Santiago Trujillo Relatório

0

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

about 4 years ago · Santiago Trujillo Relatório

0

note PHP7 = is_dst parameter has been removed.

$month_options="";
for( $i = 1; $i <= 12; $i++ ) {
    /* $month_num = str_pad( $i, 2, 0, STR_PAD_LEFT ); -- there is no use for this line */ 
    $month_name = date( 'F', mktime( 0, 0, 0, $i + 1, 0, 0)); // is_dst parameter has been removed.
    /* $selected=""; -- there is no use for this line */
    /* $month_options.$month_name."<br/>"; -- you are not correctly set this paramter */
    $month_options .= $month_name."<br/>"; // so if you do like this, it will be correct
}
echo $month_options;
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda