tags:

views:

24

answers:

1

I can't explain this. I have the following:

     $time += $res['timezone']; (The array equates to -5*3600 (EST))
     return gmstrftime('%c',$time);

When I echo $res['timezone'], I get "-5*3600" which is correct. When I put the array value in front of the time variable, I get the incorrect time. If I comment out the array value and replace it with -5*3600, I get the correct result. Why??

+1  A: 

because the string "-5*3600" and the expression -5*3600 aren't the same thing. You could try to put eval around the array value, like so:

 $time += eval($res['timezone']); //(The array equates to -5*3600 (EST))
 return gmstrftime('%c',$time);

Note that this is a very bad idea, as it is both slow and insecure. If you want to store -5*3600 in the array, then calculate the value and store the result in the array:

$res['timezone'] = -5*3600;
Marius
Beat me too it!(Just for kicks, do a var_dump on it's value look @ the results.)
Mark Tomlin
Thanks Marius. You're right. brb with the results
Jim
A var_dump gives me: -5*3600
Jim
I tried eval() but that didn't do anything.
Jim
I got it, thanks Marius. I will just store the difference in the database instead of the equasion.
Jim