![]() |
Nested if's or is there a better way?
Hey Guys and Gals,
I know when I have written something for PHP there is a million ways to do the same thing. My question is what is the best way with if's and elseif's? What I want to do is I have 4 variables to compare. If variable 1 is less than 30 then do this that is fairly simple. However, the issue becomes harder when I have to compare all 4 variables at once. Var1 could be equal to 8- but var 2, 3 and 4 are all less than 400 so do this. or 2 and 4 could be greater than 400 but 3 less than, then do this. The way I do it now is this Code:
if($row[2]>='80' && $data[1]<'300' && $data[4]>='400' && $data[6]>=400)Code:
if($row[2]>='80'){Suggestions? |
I'd definetely prefer the first one, because the code is easier to understand, simpler - and looks just nicer.
|
I do as well, I just don't want to miss any cases.
|
Yes. The first way, I suppose. Although lay it out a little better by adding more spaces:
php Code:
|
| All times are GMT. The time now is 01:50 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0