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

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to implement an entity bound odata action in olingo v4.3 -