Mamen
Mamen

Reputation: 1446

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?

Upvotes: 0

Views: 398

Answers (2)

poli_g
poli_g

Reputation: 639

I think your problem is that you write "+ $x month"and it doesn't recognize $x is a variable.

Try writing "+ " .$x. " month" instead.

Upvotes: 0

AbraCadaver
AbraCadaver

Reputation: 79024

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);
}

Upvotes: 1

Related Questions