You are here: Re: Variable substitution to replace switch « PHP Programming Language « IT news, forums, messages
Re: Variable substitution to replace switch

Posted by Schraalhans Keukenmeester on 05/31/07 13:27

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@the.spamtrapexample.nl
[Remove the lowercase part of Spamtrap to send me a message]

"strcmp('apples','oranges') < 0"

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация