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
Post a Comment