[nflug] PHP (switch vs. nested if)

Timothy Finucane speljamr at speljamr.com
Thu Feb 21 11:43:32 EST 2008


A switch is the most efficient method. I'm not sure how much speed
performance is affected, but nested ifs would make the code difficult to
read.

-- 
Timothy J. Finucane

http://www.speljamr.com

Facebook: http://www.facebook.com/p/Timothy_J_Finucane/682422189



On 2/21/08, Rob Dege <livemotion at gmail.com> wrote:
>
>
> Hi, I'm wondering which would provide faster processing time based on the
> web page I'm building.
>
> I have a variable, let's call it $num.  $num is an int that can be
> anywhere from 1 to 80.  Based on $num's value, an array is assigned that is
> then used on the web page.  Since this is for a web page, I want to minimize
> the wait time as much as possible, and I'm guessing that this could be a
> potential bottleneck.  I have not written the code yet, so I can't compare
> load times.  I'm considering this more of a "do it the preferred way the
> first time".
>
> So I'm curious as to which would be faster, a simple switch with 80
> possible cases, or a "nested if" that uses a sorting algorithm;  or perhaps
> even more plausible, a combination of the two.
>
> Any random thoughts are appreciated :)
>
> --
> -Rob
>
> Ben Franklin Quote: "They that can give up essential liberty to obtain a
> little temporary safety deserve neither liberty nor safety."
> _______________________________________________
> nflug mailing list
> nflug at nflug.org
> http://www.nflug.org/mailman/listinfo/nflug
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.nflug.org/pipermail/nflug/attachments/20080221/8563e7bc/attachment-0001.html


More information about the nflug mailing list