Php if

From CoderLearner
Jump to: navigation, search


if is the most important part in PHP, and it uses to check the condition for TRUE or FALSE.

Syntax if


Example 1

  • If I feel hurt, I will cry.

$hurt = 1;

if ($hurt) {
	echo 'I will cry';

Output: By set $hurt=1 it make the statement always true

I will cry

Example 2

  • If you're not study hard, you fail the exam.
  •  ! is make the statement or the condition to become a nagative.

$study_hard = 0;

if (!$study_hard) {
	echo 'you fail the exam.';


you fail the exam.

Example 3


$a = 10;
$b = -100;

if ($a > $b) {
	echo '$a is bignner than $b';

if ($b > $a) {
	echo '$b is larger than $a';


$a is bignner than $b