Re: Array mysteries
| From: | tedd | Date: | Sun, 11 Mar 2007 18:59:27 +0000 |
| Subject: | Re: Array mysteries | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-250245@lists.php.net to get a copy of this message | ||
At 12:02 PM -0500 3/11/07, Edward Vermillion wrote:
On Mar 11, 2007, at 10:02 AM, tedd wrote:Ed It's just another way to look at a possible solution. As for the cost, what are we talking about? I doubt that a "typical" application would show any discernable difference in execution times. One could test this easy enough by running both through 50k loops, but even then I doubt that the times would be that much different -- but I may be wrong, been there before. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.comAt 3:05 PM +0100 3/11/07, Tijnema ! wrote:But what's the cost of this in a loop, rebuilding the array each time, as compared to a switch statement? Just another thought...On 3/11/07, tedd <<mailto:tedd@sperling.com>tedd@sperling.com> wrote: At 10:05 AM +0100 3/11/07, Tijnema ! wrote:It's the technique and not the specific data thing I was addressing. When I'm confronted with a case condition, I typically use the switch statement. But, your solution provided me with another way to look at that. Cheers, tedd- You could define $wdays inside the function function convert_from_weekday ($weekday) { $wdays = array (0 => "Sonntag" ,1 => "Montag" ,2 => "Dienstag" ,3 => "Mittwoch" ,4 => "Donnerstag" ,5 => "Freitag" ,6 => "Samstag" ); return $wdays[$weekday]; } $day = convert_from_weekday(0) // $day = "Sonntag"Tijnema: That's also a shorter version of a simple switch statement. I haven't thought of, or seen, that before -- thanks. tedd Yeah it is, but i just used moved his $wdays inside the function... but well, there are ofcourse a lot of other options, as date("l") would also return the day of the month :) Tijnema