if in php code example
Example 1: php elseif
<?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";
}
?>
Example 2: php if else
<?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";
}
?>
Example 3: php if
<?php
if ($a > $b) {
echo "a is bigger than b";
$b = $a;
}
?>
Example 4: php if elseif
$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';
}
Example 5: php if
<?php
if ($a > $b)
echo "a is bigger than b";
?>
Example 6: php if simple
echo empty($address['street2']) ? "Street2 is empty!" : $address['street2'];