02-09-2009, 08:31 PM
|
#1 (permalink)
|
|
The Visitor
Join Date: Feb 2009
Posts: 4
Thanks: 0
|
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)
I know that I could also do it another way like this:
Code:
if($row[2]>='80'){
if ($data[1]<'300') {
if ($data[4]>='400') {
if ($data[6]>=400){
}
}
}
}
I am just not sure which would be easier, as well there might be a different way to do this. The first way seems to be too specific and I might miss some cases. The second way would be 100% sure not to miss any cases but seems to be way more coding than I need as well not the right way to do it.
Suggestions?
|
|
|
|