1 conditional 2 orders at a same time

<?php 
$myVariable="yes";

if ($myVariable == "yes") $yesORno="yes";
else 
$yesORno="no";

if ($myVariable == "yes") include "yes.php";
else 
include "no.php";
?>

I have the code above.
If the value of $myVariable is “yes,”
The value of $yesORno will be “yes” and it includes “yes.php.”

I like to use “if” just one time for it.
The code below is one of my trials for it. But it doesn’t work as I expected.

<?php 

$myVariable="yes";

if ($myVariable == "yes") 
$yesORno="yes";
include "yes.php";

else 

$yesORno="no";
include "no.php";
?> 

Awww, you were almost there!
You need curly brackets:

<?php 

$myVariable="yes";

if ($myVariable == "yes")
{
  $yesORno="yes";
  include "yes.php";
}
else 
{
  $yesORno="no";
  include "no.php";
}
?> 

Alternatively, you could also do it like this:

<?php 

$myVariable="yes";

if ($myVariable == "yes")
  $yesORno="yes";
else 
  $yesORno="no";
include $yesOrNo.".php";
?> 

:slight_smile:

Off Topic:

This is a very good example of why imho it is good programming practice to include the curly brackets even when they are optional when you have only 1 statement after an IF or ELSE.

It’s very easy to forget to add them later on if you add more lines of code to the original single line of code after an IF or ELSE.