PHP If Else

PHP Support conditional statements like if and if..else statements.in this topic we discuss on simple if and if..else statements the following syntax and example of both type.

IF

Use the if statements to execute some code only if specified condition is true.the following syntax and example of if.

Syntax


<?php

if(condition)
{
	//Code to be Executed if Condition is True
}

?>							
							

Example


<?php

	$a=10;
	if($a<10)
	{
		echo "The Value is Less Than 10";
	}

  ?>						
							

IF..Else

Use the if..else statement to execute some code if a condition is true and another code if condition is false.the following syntax and example of if..else.

Syntax


<?php

if(condition)
{
	//Code to be Executed if Condition is True
}
else
{
	//Code to be Executed if Condition is False
}

?>								
							

Example


<?php

	$a=20;
	if($a<=15)
	{
		echo "The Value is Less Than 20";
	}
	else
	{
		echo "The Value is Greater Than 20";
	}

?>							
							
Share Share on Facebook Share on Twitter Share on Google+ Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit