Mamen Mamen - 6 months ago 13
PHP Question

A non well formed numeric value encountered

i have some problem with my syntax, this is my syntax:

for($x=1;$x<=12;$x++){
$date_a=strtotime("+ $x month", $a['date_start']);
$end=date('d-m-Y',$date_a);

}


then appears error A non well formed numeric value encountered in this
$date_a=strtotime("+ $x month", $a['date_start']);


anyone can help me?

Answer

You haven't shown $a['date_start'] but if it is a valid date format that can be converted to a timestamp, try:

$date_a = strtotime("+ $x month", strtotime($a['date_start']));

Or do it once up front:

$start = strtotime($a['date_start']);

for($x=1;$x<=12;$x++){
    $date_a = strtotime("+ $x month", $start);                          
    $end = date('d-m-Y', $date_a);
}
Comments