Re: Variable substitution to replace switch
- From: Schraalhans Keukenmeester <Schraalhans@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 31 May 2007 15:27:23 +0200
At Thu, 31 May 2007 06:02:30 -0700, damezumari let h(is|er) monkeys type:
http://www.phpbuilder.net/columns/akent20000610.php3?page=5[snip]
switch ($type)
{
case 'hours':
$hours = $add + $hours;
break;
case 'minutes':
$minutes = $add + $minutes;
break;
case 'seconds':
$seconds = $add + $seconds;
break;
case 'months':
$months = $add + $months;
break;
case 'days':
$days = $add + $days;
break;
case 'years':
$years = $add + $years;
break;
}
$timestamp = mktime($hours, $minutes, $seconds, $months, $days,
$years);
$newdatetime = date('Y-m-d H:i:s', $timestamp);
return ($newdatetime);
}
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?
$$type += $add;
But, why are you reinventing the strtotime function?
$dayaftertomorrow = date('D M j G:i:s T Y',strtotime('+2 days'));
HTH,
Sh.
--
Schraalhans Keukenmeester - schraalhans@xxxxxxxxxxxxxxxxxxxxxx
[Remove the lowercase part of Spamtrap to send me a message]
"strcmp('apples','oranges') < 0"
.
- Follow-Ups:
- Re: Variable substitution to replace switch
- From: damezumari
- Re: Variable substitution to replace switch
- References:
- Variable substitution to replace switch
- From: damezumari
- Variable substitution to replace switch
- Prev by Date: Re: Variable substitution to replace switch
- Next by Date: PHP/mySQL Forum/BBoard Recommendations
- Previous by thread: Re: Variable substitution to replace switch
- Next by thread: Re: Variable substitution to replace switch
- Index(es):
Relevant Pages
|