Posted By:
9 Mar, 2014 12:17 am PST

How to write if statement block in php?

 How to write if statement block in php?

When you want to make decision at particular time while writing the code you have to use this conditional control structures.

If condition evaluated to be true, then block of code within if executed. Else block of code skipped and next instruction gets executed

 

Syntax :-

 

if(condition)

{

// write your code here

}

 

//to find bigger number out of two

 
 

<? php

echo " <h2 > " ;

echo " To find bigger number " ;

echo " <br > < br > " ;

$a = rand (0 ,100) ;// rand ( int min , int max ) this function returns

$b = rand (0 ,100) ;// a pseudo - random integer between " min " and "

//max " value .

echo " a ={ $a } <br > < br > b ={ $b } <br > < br > " ;

$bigger = $a ;

if ( $b > $a ) // condition

{

$bigger =$b ; // statement

}

echo " { $bigger } is bigger " ;

?>

IfStatementBlock.php

 

 

 

 

 

 

 

 

 

 

 

 

 

 

IfStatementOutput 



How to use if statement in PHP

 

if is used when we want to check a specified or a particular condition.It execute when the condition specified is true.

SYNTAX:

if (condition)

{

code to be executed if condition is true;

}

 

//Code to show how to use if statement in PHP

<html>

<body>

<?php

$a=30;

$b=9;

if ($a>$b)

{

echo "Here a is greater than b";

}

?>

</body>

</html>

 

/*Output of the above program is:

Here a is greater than b

*/

 

Was it useful?  




Please login to reply to this problem.