Re: Variable substitution to replace switch



damezumari kirjoitti:
Thanks!

strtotime()= it is!

It would still be good to get my question answered:

"It works OK, but I would like to replace the switch statement with
one
statement a la:

&$type = &$type + $add;

Can that be done in php?"

If they are unix timestamps and seconds yes. If not, you need to convert them into such first. This is what strtotime does, and then using date again reverses it.

You can do this:
$time0 = time(); // get a unix timestamp
$interval = 60*60*24; // one day in seconds.
$time0 += $interval; // add an interval to timestamp
echo date('Y-m-d H:i:s', $time0); // tomorrow

But this is good just for timestamps. Just remeber, working with timestamps is dreadful when it comes to daylight saving, leap years and other temporal oddities.

--
Rami.Elomaa@xxxxxxxxx

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
.



Relevant Pages

  • Re: Variable substitution to replace switch
    ... Rami Elomaa kirjoitti: ... strtotime()= it is! ... but I would like to replace the switch statement with ... "Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan ...
    (comp.lang.php)
  • Re: strtotime("2007 Jul 10") fails
    ... strtotime doesn't recognize this format and returns FALSE. ... Is there a direct way to convert times from this format into ... timestamps, other than my having to whip up a simple parsing routine? ...
    (comp.lang.php)