Conditional Code (Day-1)
Conditional Code (Day-1)
<?php
if ($c > $d)
{
echo "c is bigger than d";
}
?>
In the above example, only if the condition "$c>$d" is true,
the message "c is bigger than d" is displayed
If( ){
condition
// your additional code goes here
// . . .
( parentheses
)
[ brackets
]
{ braces
}
true or false?
If( $d
$a
$b
$c )===
<{20
condition
==
>
!= 50
100
99 99 Code block
echo “it’s true!”;
// . . .
If( $a == $b ){
$a = 5;
$b = 10;
If( $a = $b ){
// always true!
}
= assignment
== equality
===strict equality
If( $a == $b ){ …
If( $a != $b ){ …
If( $a === $b ){ …
If( $a !== $b ){ …
If( $a > $b ){ …
If( $a < $b ){ …
If( $a >= $b ){ …
If( $a <= $b ){ …
© Copyright 2017 Hidaya Institute of Science and Technology
Using comparison operators
<?php
$c = 10;
$d = 20;
if ($c > $d) {
echo "C is bigger than d";
}
else {
echo "D is bigger than c";
}
?>
Result: D is bigger than C
In the above example in the if the condition "$c>$d" is true then the
message "C is bigger than D" is displayed, else the message "D is bigger than
C" is displayed.
© Copyright 2017 Hidaya Institute of Science and Technology