I'm new to learning how to program. And I'm wondering what the best way is to handle the problem where you got a double if statement, with both having the same Else result.
Take for instance the following double if statement.
if (isset($x)) {
$y = doSomething($x);
if ($y == "something") {
do result A;
}
else {
do result B;
}
}
else {
do result B;
}
It doesn't seem like a smart idea to write result B multiple times. Now what are the different ways to prevent having to write result B multiple times?
One can try making 1 combined if statement, but this doesn't seem always possible (for instance when checking with isset() if a variable exists).
if (isset($x) && $y) { etc. }
What other options are there?
PS. I'm also open for other suggestions to help improve my code, like how to write if(isset($x)) in a nicer way.