Example : How to use if control statement in Php ?

<!DOCTYPE html>
<html>
	<body>
	   <?php
			$t = 50;
			if ($t > 20) 
			{
			  echo "The value is Greater than 20";
			}

			if ($t < 20)
			{
			  echo "The value is Smaller than 20";
			}

			if ($t == 20)
			{
			  echo "The value is equal to 20";
			}
	   ?>
	</body>
</html> 

Example : How to use  if-else control statement in Php ?

<!DOCTYPE html>
<html>
	<body>
	   <?php
		$t = 20;
		if ($t > 20) 
		{
		  echo "The value is Greater than 20";
		}
		else
		{
		  echo "The value is either Smaller than/equal to 20";
		}			
	   ?>
	</body>
</html> 

Example : How to use  nested if-else control statement in Php ?

<!DOCTYPE html>
<html>
	<body>
	   <?php
		$t = 20;
		if ($t > 20) 
		{
		  echo "The value is Greater than 20";
		}
		else			
		{
			if($t<20)
			{
				echo "The value is Smaller than 20";
			}
			else
			{
				echo "The value is equal to 20";
			}
		}
	   ?>
	</body>
</html> 

Example : How to use  if-elseif-else control statement in Php ?

<!DOCTYPE html>
<html>
	<body>
	   <?php
		$t = 20;
		if ($t > 20) 
		{
		  echo "The value is Greater than 20";
		}
		elseif($t<20)
		{
		  echo "The value is Smaller than 20";
		}
		else
		{
		  echo "The value is equal to 20";
		}
	   ?>
	</body>
</html> 

Example : How to use  switch case control statement in Php ?

<!DOCTYPE html>
<html>
	<body>
	   <?php
		$val = 1;
		   switch ($val) 
		     {
		        case 1:
			  echo "Sunday";
			  break;
			case 2:
			  echo "Monday";
			  break;
			case 3:
			  echo "Tuesday";
			  break;
			case 3:
			  echo "Wednesday";
			  break;
			case 3:
			  echo "Friday";
			  break;
			case 3:
			  echo "Saturday";
			  break;
			default:
			  echo "Incorrect Choice Entered, Change it";
		    }
	  ?>
     </body>
</html> 

Example : How to use  for loop control statement in Php ?

<!DOCTYPE html>
<html>
	<body>
	   <?php
		echo "The numbers are : = ";
		for ($x = 5; $x <= 15; $x++) 
		{
		   echo $x."  " ;
		}		
	   ?>
	</body>
</html>
 
Output :
The numbers are : = 5 6 7 8 9 10 11 12 13 14 15

Example : How to use  while loop control statement in Php ?

<!DOCTYPE html>
<html>
	<body>
	   <?php
		$x = 5;
		echo "The numbers are : = ";
		while( $x <= 15) 
		{
		   echo $x."  " ;
		   $x++;
		}		
	   ?>
	</body>
</html>

Output :
The numbers are : = 5 6 7 8 9 10 11 12 13 14 15

Example : How to use do while loop control statement in Php ?

<!DOCTYPE html>
<html>
	<body>
	   <?php
		$x = 5;
		echo "The numbers are : = ";
		do
		{
		   echo $x."  " ;
		   $x++;
		}while( $x <= 15) ;		
	   ?>
	</body>
</html>

Example : How to use for each loop control statement in Php ?

<!DOCTYPE html>
<html>
	<body>
	   <?php
		$vowels = array("A", "E", "I", "O", "U"); 
		foreach ($vowels as $x) 
		{
	            echo "$x <br>";
		}	
	   ?>
	</body>
</html>

NB:
This loop applied in Array only.

Example : How to use break statement in Php ?

<!DOCTYPE html>
<html>
	<body>
	   <?php
		echo "The numbers are : = ";
		for ($x = 5; $x <= 15; $x++) 
		{
		   if ($x==10)
		   {
			   break;
		   }
		   
		   echo $x."  " ;
		}		
	   ?>
	</body>
</html>

Output:
The numbers are : = 5 6 7 8 9

Example : How to use continue statement in Php ?

<!DOCTYPE html>
<html>
	<body>
	   <?php
		echo "The numbers are : = ";
		for ($x = 5; $x <= 15; $x++) 
		{
		   if ($x==10)
		   {
			   continue;
		   }
		   
		   echo $x."  " ;
		}		
	   ?>
	</body>
</html>

Output :
The numbers are : = 5 6 7 8 9 11 12 13 14 15

 396 total views,  1 views today

Categories: Php

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.