<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>The cleanest would be for your arrays to be a single array of
arrays..<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>For example:<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>$myarray={1,2,3,4,5};<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>$myotherarray={5,6,7,8,9};<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Would be a pain, but<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>$arrays[0]={</span> <span style='font-size:11.0pt;font-family:
"Calibri","sans-serif";color:#1F497D'>1,2,3,4,5};<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>$arrays[1]={5,6,7,8,9};<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Then you simply have a single assignment:<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>$myarraytouse=$array[$num];<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Mark<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
nflug-bounces@nflug.org [mailto:nflug-bounces@nflug.org] <b>On Behalf Of </b>Rob
Dege<br>
<b>Sent:</b> Thursday, February 21, 2008 2:57 PM<br>
<b>To:</b> nflug@nflug.org<br>
<b>Subject:</b> Re: [nflug] PHP (switch vs. nested if)<o:p></o:p></span></p>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal style='margin-bottom:12.0pt'><br>
I'm not took concerned about readability. I already code in the style of
spaghetti, so cleanliness is not my first concern. I think I might break
the switch into chunks of 20, and then use a single if statement to determine
which switch to compare the variable against.<br>
<br>
Thanks for the replies though.<br>
<br>
Bob, I know not of this 'C' you language speak of... unless you forgot to add
the '#' after it ;)<br>
<br>
-Rob<o:p></o:p></p>
<div>
<p class=MsoNormal>On Thu, Feb 21, 2008 at 1:11 PM, Robert Meyer <<a
href="mailto:meyer_rm@yahoo.com">meyer_rm@yahoo.com</a>> wrote:<o:p></o:p></p>
<div>
<div>
<p class=MsoNormal>Well, if you write the code in C, just create an array of
addresses of arrays and just directly access the array by position. Then
you don't even need any comparisons. :-)<br>
<br>
Cheers!<br>
<br>
Bob<o:p></o:p></p>
<div>
<p class=MsoNormal> <o:p></o:p></p>
</div>
<p class=MsoNormal>--<br>
"When once you have tasted flight, you will forever walk the earth with
your eyes turned skyward, for there you have been, and there you will always
long to return."<br>
--Leonardo da Vinci<o:p></o:p></p>
<div>
<div>
<div>
<p class=MsoNormal style='margin-bottom:12.0pt'><o:p> </o:p></p>
<div>
<p class=MsoNormal>----- Original Message ----<br>
From: Franklin Kumro Jr <<a href="mailto:fkumro@gmail.com" target="_blank">fkumro@gmail.com</a>><br>
To: <a href="mailto:nflug@nflug.org" target="_blank">nflug@nflug.org</a><br>
Sent: Thursday, February 21, 2008 12:18:07 PM<br>
Subject: Re: [nflug] PHP (switch vs. nested if)<br>
<br>
I would agree that a switch statement would be the preferred method. <br>
Multiple nested if statements hurt code readability, let alone a 1-80 <br>
range.<br>
<br>
-Frank<br>
On Feb 21, 2008, at 11:43 AM, Timothy Finucane wrote:<br>
<br>
> A switch is the most efficient method. I'm not sure how much speed <br>
> performance is affected, but nested ifs would make the code <br>
> difficult to read.<br>
><br>
> -- <br>
> Timothy J. Finucane<br>
><br>
> <a href="http://www.speljamr.com" target="_blank">http://www.speljamr.com</a><br>
><br>
> Facebook: <a href="http://www.facebook.com/p/Timothy_J_Finucane/682422189"
target="_blank">http://www.facebook.com/p/Timothy_J_Finucane/682422189</a><br>
><br>
><br>
><br>
> On 2/21/08, Rob Dege <<a href="mailto:livemotion@gmail.com"
target="_blank">livemotion@gmail.com</a>> wrote:<br>
> Hi, I'm wondering which would provide faster processing time based <br>
> on the web page I'm building.<br>
><br>
> I have a variable, let's call it $num. $num is an int that can
be <br>
> anywhere from 1 to 80. Based on $num's value, an array is
assigned <br>
> that is then used on the web page. Since this is for a web page,
I <br>
> want to minimize the wait time as much as possible, and I'm guessing
<br>
> that this could be a potential bottleneck. I have not written
the <br>
> code yet, so I can't compare load times. I'm considering this
more <br>
> of a "do it the preferred way the first time".<br>
><br>
> So I'm curious as to which would be faster, a simple switch with 80 <br>
> possible cases, or a "nested if" that uses a sorting
algorithm; or <br>
> perhaps even more plausible, a combination of the two.<br>
><br>
> Any random thoughts are appreciated :)<br>
><br>
> -- <br>
> -Rob<br>
><br>
> Ben Franklin Quote: "They that can give up essential liberty to
<br>
> obtain a little temporary safety deserve neither liberty nor safety."<br>
> _______________________________________________<br>
> nflug mailing list<br>
> <a href="mailto:nflug@nflug.org" target="_blank">nflug@nflug.org</a><br>
> <a href="http://www.nflug.org/mailman/listinfo/nflug" target="_blank">http://www.nflug.org/mailman/listinfo/nflug</a><br>
><br>
><br>
><br>
><br>
><br>
> _______________________________________________<br>
> nflug mailing list<br>
> <a href="mailto:nflug@nflug.org" target="_blank">nflug@nflug.org</a><br>
> <a href="http://www.nflug.org/mailman/listinfo/nflug" target="_blank">http://www.nflug.org/mailman/listinfo/nflug</a><br>
<br>
_______________________________________________<br>
nflug mailing list<br>
<a href="mailto:nflug@nflug.org" target="_blank">nflug@nflug.org</a><br>
<a href="http://www.nflug.org/mailman/listinfo/nflug" target="_blank">http://www.nflug.org/mailman/listinfo/nflug</a><o:p></o:p></p>
</div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</div>
</div>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
<div class=MsoNormal align=center style='text-align:center'>
<hr size=1 width="100%" align=center>
</div>
<p class=MsoNormal>Looking for last minute shopping deals? <a
href="http://us.rd.yahoo.com/evt=51734/*http:/tools.search.yahoo.com/newsearch/category.php?category=shopping"
target="_blank">Find them fast with Yahoo! Search.</a><o:p></o:p></p>
</div>
</div>
<p class=MsoNormal style='margin-bottom:12.0pt'><br>
_______________________________________________<br>
nflug mailing list<br>
<a href="mailto:nflug@nflug.org">nflug@nflug.org</a><br>
<a href="http://www.nflug.org/mailman/listinfo/nflug" target="_blank">http://www.nflug.org/mailman/listinfo/nflug</a><o:p></o:p></p>
</div>
<p class=MsoNormal><br>
<br clear=all>
<br>
-- <br>
-Rob<br>
<br>
Ben Franklin Quote: "They that can give up essential liberty to obtain a
little temporary safety deserve neither liberty nor safety." <o:p></o:p></p>
</div>
</body>
</html>