php - How to reduce nested if-else condition? -


i lot of nested if-else condition in code. it's 34 times it. know, it's driving me crazy. please tell me how reduce it. thank you.

and here code :

if ($input_age > $age_min && $input_age <$age_max){  if ($input_heigh > $heigh_min && $input_heigh < $heigh_max){     if ($input_ds == "yes" && $ds_val=="yes" ){      //some calculation     }     else if ($input_ds == "no" && $ds_val=="yes"){      //some calculation      }     else if ($input_ds == "yes" && $ds_val=="no"){      //some calculation      }     else if ($input_ds == "no" && $ds_val=="no"){       //some calculation        } } else if ($input_heigh < $heigh_min || $input_heigh > $heigh_max){     if ($input_ds == "yes" && $ds_val=="yes" ){     //some calculation      }     else if ($input_ds == "no" && $ds_val=="yes" ){      //some calculation      }      else if ($input_ds == "yes" && $ds_val=="no"){      //some calculation      }     else if ($input_ds == "no" && $ds_val=="no" ){      //some calculation      } } 

and many more if-else conditon

i suggest use switch in such cases more readable. here simple example:

switch($input_ds.$ds_val){    case 'yesyes':       //some calculations       break;    case 'yesno':       //some calculations       break;    case 'noyes':       //some calculations       break;    case 'nono':       //some calculations       break; } 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -