Jump to: navigation, search

Php if

From w3cyberlearnings

Contents

if

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

Syntax if

if(expr)
 statement

Example 1

  • If I feel hurt, I will cry.
<?php

$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.
<?php

$study_hard = 0;

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

Output

you fail the exam.

Example 3

<?php

$a = 10;
$b = -100;

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

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

Output

$a is bignner than $b


Related Links


Navigation
Web
SQL
MISC
References