Repeat For Error Function [closed]

0

I'm having an error inside a for loop. The Error gives me to the Function line.

$Valor = "SELECT max(id) FROM tb_empresa";
For ($contatador = 0; $contador = $Valor; $contador++){

//Código 

function estaParaExpirar($data, $dias=10) {
if (!strtotime($data) || empty($data)) return false;
return(strtotime($data) < strtotime("+".$dias. "days") );
}

Fatal error: Can not redeclare thisToExpire ()

    
asked by anonymous 25.08.2014 / 10:59

1 answer

2

It gives an error because it has set the function toExpire within a loop, which causes each loop cycle and function to be declared and a function can only be declared once within its scope. Here you have two options: declare the function outside the loop and call inside the loop, or remove the function declaration and execute the function code inside the loop

$Valor = "SELECT max(id) FROM tb_empresa";
For ($contatador = 0; $contador == $Valor; $contador++){

//Código 

if (!strtotime($data) || empty($data)) 
    return  false;

return (strtotime($data) < strtotime("+".$dias. "days") );


}
    
25.08.2014 / 12:04