Hello all,
As a PHP programmer faced a lot with (deepgoing) statements I'm curious how you handle this. Are you using switch, if-elseif-else or if-else structures?
I personally prefer using the switch selector when dealing with more than 2 cases. Is this also the best way from a performance perspective? And how about nested statements?
I'm curious to your preferred methods and answers.
Example
The need of three-option-selector:
Using switch:
switch($option)
{
case 1 : $result= "foo"; break;
case 2 : $result= "bar"; break;
default : $result= "foobar";
}
Using if-elseif-else
if($option == 1)
{
$result= "foo";
} elseif ($option == 2)
{
$result= "bar";
} else
{
$result= "foobar";
}
Using if-if-else
if($option == 1)
{
$handle = "foo";
}
if($option == 2)
{
$result = "bar";
}
else
{
$result = "foobar";
}