it seems inefficient me write multiple conditions same action,,, example
if ( (condition_one || (condition_two && condition_three) ) { // ... } elseif ( condition_two && condition_three) { // same before ... } else { // ... }
would there valid approach accomplishing this? condition_two , condition_three have executed separately condition_one...
if ( (condition_one || (condition_two && condition_three) ) { // ... } else { // ... }
in other words,,, there way, unaware of, this:
if ( ( $a < $b || ( $a <= $b && $c = $d ) ) { echo 'foo'; } else { echo 'bar'; }
rather this:
if ( ( $a < $b ) { echo 'foo'; } elseif ( $a <= $b && $c = $d ) { echo 'foo'; } else { echo 'bar'; }
you can test easy had paren
<?php function testnest($a, $b, $c, $d){ if ($a < $b || ( $a <= $b && $c = $d )) { echo 'foo'; } else { echo 'bar'; } } testnest(3, 2, 3, 2); //bar testnest(1, 2, 3, 2); //foo function testelif($a, $b, $c, $d){ if ($a < $b ){ echo 'foo'; } elseif ( $a <= $b && $c = $d ) { echo 'foo'; } else { echo 'bar'; } } testelif(3, 2, 3, 2); //bar testelif(1, 2, 3, 2); //foo
i'll let come more examples there no need elseif
Comments
Post a Comment