xxxxxxxxxx
<? if ($condition): ?>
<p>Content</p>
<? elseif ($other_condition): ?>
<p>Other Content</p>
<? else: ?>
<p>Default Content</p>
<? endif; ?>
xxxxxxxxxx
<?php
if ($a > $b) {
echo "a is bigger than b";
} elseif ($a == $b) {
echo "a is equal to b";
} else {
echo "a is smaller than b";
}
?>
xxxxxxxxxx
<?php
if ($a > $b) {
echo "a is bigger than b";
} elseif ($a == $b) {
echo "a is equal to b";
} else {
echo "a is smaller than b";
}
?>
xxxxxxxxxx
$a = random_int(0, 10);
$b = random_int(0, 10);
if ($a > $b) {
echo 'a is greater than b';
} elseif ($a == $b) {
echo 'a is equal to b';
} else {
echo 'a is less than b';
}
xxxxxxxxxx
if ($age < 18) {
echo "Sorry, you are not old enough to vote.";
} elseif ($age >= 18 && $age < 21) {
echo "You can vote, but you can't drink.";
} else {
echo "You can vote and drink!";
}
xxxxxxxxxx
$fav_fruit = "orange";
if ($fav_fruit === "banana"){
echo "Enjoy the banana!";
} elseif ($fav_fruit === "apple"){
echo "Enjoy the apple!";
} elseif ($fav_fruit === "orange"){
echo "Enjoy the orange!";
} else {
echo "Enjoy the fruit!";
}
// Prints: Enjoy the orange!
xxxxxxxxxx
<?php
if ($a > $b) {
echo "a is greater than b";
} else {
echo "a is NOT greater than b";
}
?>
xxxxxxxxxx
<?php
$a=0;
if($a==0)
{
echo “good”;
}
else if ($a >=1 && $a<=20)
{
echo “great”;
}
else if($a>20)
{
echo “excellent”;
}
else
{
echo “no good”;
}
?>
xxxxxxxxxx
echo 'Your score is: '.($score > 10 ? ($age > 10 ? 'Average' : 'Exceptional') : ($age > 10 ? 'Horrible' : 'Average') );