you want to perform different actions for different decisions. You can use conditional statements .
The php conditional statement are :
- if statement - It is used to execute an instruction or Block of instructions only if a condition is fulfilled.
- if...else statement - is used when a different sequence of intructions is to be executed depending on the logical value ( True / False ) of the condition evauated.
- if...elseif....else statement (Nested if...else statement) - selects one of several blocks of code to be executed.
- switch statement - selects one of many blocks of code to be executed.
Syntax -
PHP - The if Statement
if (condition)
{
code to be executed if condition is true;
}
PHP - The if...else Statement
if (condition)
{
code to be executed
if condition is true;
}
else
{
code to be executed
if condition is false;
}
PHP - The if...elseif....else Statement
if (condition)
{
code to be executed
if condition is true;
}
elseif (condition)
{
code to be executed if condition is true;
}
else
{
code to be executed if condition is false;
}
PHP - The switch Statement
switch (n)
{
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed
if n=label2;
break;.
default:
code to be executed
if n is different from all labels;
}
Comments
Post a Comment