Bootstrap Templates Bundle

Monday, February 2, 2015

php if else sample code

This code is for those, who are facing problem with php if else


Sample 1: 


<?php if (condition): ?>
html code to run if condition is true
<?php else: ?>
html code to run if condition is false
<?php endif ?>

Sample 2: 


<?php
if(condition) { ?> 
html code to run if condition is true
<?php } ?>


Sample 3: 


<?php
     $var=1;
     if($var == 2) {
          echo “The if statement is true”;
         // or any html code to run if condition is true
     } else {
          echo “The if statement is not true”;
        // or any html code to run if condition is true
     }

?>


Sample 4:  

 The if…elseif…else Statement



<?php 
 $var=1; 
 $var2=1; 
 if($var == 2) { 
 echo “The if statement is true”; 
 } 
elseif($var == $var2) { 
 echo “The second if statement is true”; 
 } 
else { 
 echo “None of the first if statement where true”; 
 } 
?>


Sample 5:

<?php 
if ( $number_three == 3 ) {
echo "The if statement evaluated to true";
} else {
echo "The if statement evaluated to false";
}
?>

No comments:

Post a Comment

Wokiee React eCommerce Template