php if and or code example

Example 1: php or

$num1 = 5;
$num2 = 10;
$num1 === 5 or $num2 === 6;
// Shorthand
$num1 === 5 || $num2 === 6;

Example 2: 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 3: if not php

$a = true;

if(!$a) {
	echo "False"; // Will return this
} else {
	echo "True";
}

Example 4: php if less than number

<?php
if ($a > $b)
  echo "a is bigger than b";
?>

Tags:

Php Example