PHP If... Else statements

PHP If... Else statements are similar to other languages but important is its conditional operator’s.
If you have Knowles on its conditional operations then it’s easy to implement if else statements


//PHP if else Statements
<?php
//Syntax 1
if( Condition )
{
//Execute Code
}
else
{
//Execute Code
}

//Syntax 2
if( Condition )
//Execute First Line without Braces
else
//Execute First Line without Braces
?>


Example


<?php
$Mango=1;
$Orange=2;

if ($Mango==1){
echo "Total Fruits are "+$Mango$+$Orange;    // execute first line
else
echo $Mango ;// execute first line
?>

// Output

"Total Fruits 3"

<?php
$Mango=1;
$Orange=2;

if ($Mango==1){
    $total=$Mango$+$Orange;
    echo "Total Fruits ".$total;
}
else
{  
echo $Mango ;
}
?>
Output
"Total Fruits 3"


No comments :

Post a Comment

Leave A Comment...