Conditional Statements:-
In every program you need to perform different actions for different tasks so you need to use the conditional statements to do these type of actions.
In PHP there are several types of conditional statements.
if statements:- if statement is used to execute some code inside the if block, if the specified condition is true then the code will be execute otherwise the code never execute.
Example:-
<?php
$x=0;
if($x>0)
{
echo $x;
}
?>
if else Statements:- if else statement is used to execute some code inside the if block, if the specified condition of if block is true then the code will be execute otherwise the else code should be execute.
Example:-
<?php
$x=0;
if($x>0)
{
echo "Hi";
}
else
{
echo "Bye";
}
?>
if else if Statements:- if else if statement is used to execute some code inside the multiple choice if blocks, the compiler checks all conditions till its not find the true statement, if a true statement is found the compiler does't check next if statements and if all condition are false then the else condition should be execute.
Example:-
<?php
$x=0;
if($x>0)
{
echo "Hi";
}
else if($x==0)
{
echo "Bye";
}
else
{
echo "Wrong choice";
}
?>
In every program you need to perform different actions for different tasks so you need to use the conditional statements to do these type of actions.
In PHP there are several types of conditional statements.
if statements:- if statement is used to execute some code inside the if block, if the specified condition is true then the code will be execute otherwise the code never execute.
Example:-
<?php
$x=0;
if($x>0)
{
echo $x;
}
?>
if else Statements:- if else statement is used to execute some code inside the if block, if the specified condition of if block is true then the code will be execute otherwise the else code should be execute.
Example:-
<?php
$x=0;
if($x>0)
{
echo "Hi";
}
else
{
echo "Bye";
}
?>
if else if Statements:- if else if statement is used to execute some code inside the multiple choice if blocks, the compiler checks all conditions till its not find the true statement, if a true statement is found the compiler does't check next if statements and if all condition are false then the else condition should be execute.
Example:-
<?php
$x=0;
if($x>0)
{
echo "Hi";
}
else if($x==0)
{
echo "Bye";
}
else
{
echo "Wrong choice";
}
?>
{ 1 comments... read them below or add one }
nice............
Post a Comment