Hello friends, this is my third tutorial of PHP and Today I am sharing the concept of using logical operators in PHP. Conditional operators are one of the simple and widely used feature of a programming language. So without wasting any time lets start.
Using if-else structure in PHP :
Using if-else structure in PHP :
<?php $a=10; $b=20; if($a>$b) { echo " A is Greater"; } elseif($a<$b) { echo " A is lesser"; } else { echo "A and B are equal"; } ?>Using if-else structure with multiple conditions in PHP :
<?php $c=30; $d=40; //if(($a<$c)AND($b<$d)) if(($a<$c)&&($b<$d)) { echo "A and B are larger"; } if(isset($d)) //Checks if a variable is initialized or not $d=100; echo $d; unset($d); ?>Using switch-case in PHP :
<?php $var1=2; switch($var1) { case 1 : echo "var1 is 1"; break; case 2 : echo "var1 is 2"; break; case 3 : echo "var1 is 3"; break; default : echo "var1 is unknown"; } ?>
0 comments:
Post a Comment
Note: only a member of this blog may post a comment.