php - nested if-else statement with same else code -


i have following code , want know if there better way use if-else same result other using same else 3 times?

if($condition1) {    // code condition 2    if($condition2) {       // code condition 3       if($condition3) {          $dt = $something;       } else {          $dt = "";       }    } else {       $dt = "";    } } else {    $dt = "";  } 

you rid of of else statements.

$dt = ""; // assign $dt in beginning  if ($condition1) {     // code condition 2     if ($condition2 && $condition3) {       // code condition 3       $dt = $something;     } }  

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -