Logical Expression in PHP
Today, we will talk about logical expression in PHP.
Syntax of the Logical expression are same as the other Programming languages i.e. C and java.
Syntax:
if Condition:
if(condition)
run this
if else Condition:
else
run this
Syntax of the Logical expression are same as the other Programming languages i.e. C and java.
Syntax:
if Condition:
if(condition)
run this
if else Condition:
if(condition)
run thiselse
run this
nested if else Condition:
else if
run this
if(condition)
run thiselse if
run this
else
run this
############################
PHP Code
############################
<?php
$a = 4;
$b = 5;
// if condition
if( $a > $b ) // if no curly braces is used, then only next line will be executed
echo " <br/> a is greater then b ";
echo " <br/> this will not depend on the condition ";
echo " <hr/> ";
if( $a < $b )
echo " <br/> a is less then b ";
echo " <br/> this will not depend on the condition ";
echo " <hr/> ";
if( $a > $b ) // if curly braces is used, then next line will also depend on condition
{
echo " <br/> a is greater then b";
echo " <br/> this will also depend on the condition ";
echo " <br/> this will also depend on the condition ";
}
echo " <hr/> ";
if( $a < $b )
{
echo " <br/> a is less then b ";
echo " <br/> this will also depend on the condition ";
echo " <br/> this will also depend on the condition ";
}
echo " <hr/> ";
// if else condition
if ( $a > $b )
{
echo " <br/> A is Greator then B ";
}
else
{
echo " <br/> A is not Greator then B ";
}
?>
############################
Comments
Post a Comment