condition

Estimated reading time: 1 minute

if

$a = 5;
if ($a === 5) {
  echo "${a}";
}
# 5

else

$a = 6;
if ($a === 5) {
  echo "${a}";
} else {
  echo "not 5";
}
# 5

elseif

$a = 6;
if ($a === 5) {
  echo "${a}";
} elseif ($a == 6) {
  echo "${a}";
} else {
  echo "not exist";
}
# 6

tenary condition

$a = 6;
$status = $a === 5 ? 'true' : 'false';
echo $status;
# false

switch

  • code4mk is JS lover
switch("b") {
  case "a": {
    echo "yo a";
    break;
  }
  case "b": {
    echo "yo b";
    break;
  }
  default: {
    echo "not exist";
  }
}
#  yo b

resources

php