Question: Which language construct can best represent the following series of if conditionals?<?php
if($a == 'a') {
somefunction();
} else if ($a == 'b') {
anotherfunction();
} else if ($a == 'c') {
dosomething();
} else {
donothing();
}
?>
A
B
C
D
E
A switch statement without a default case
B
A recursive function call
C
A while statement
D
It is the only representation of this logic
E
A switch statement using a default case
Note: A series of if…else if code blocks checking for a single condition as above is a perfect place to use a switch statement:
<?php switch($a) { case 'a': somefunction(); break; case 'b': anotherfunction(); break; case 'c': dosomething(); break; default: donothing(); } ?>Because there is a catch-all else condition, a default case must also be provided for that situation. Answer E is correct.