Saturday, 19 October 2013

If_else If Statement in php

If_else If Statement
This is tutorial about if_else if statement.
Code for if_else if statement(Screenshot1):-
if_else if statement in php
if_else if statement(Screenshot1)
1
2
3
4
5
6
7
8
9
10
<?php
$number= 10;
if ($number==10) {
echo 'equal to ten.';
} else if ($number==11){
echo 'Equal to eleven.';
} else{
echo 'Not equal.';
}
?>
output (Screenshot2):-
if_else if statement in php
if_else if statement(Screenshot2)
In “if_else statement” we can also evaluate one variables with many strings? For example we suppose
variable $number=10 in if_else statement as we did in “ifstatement”, its output will be equal to 10.
If value is 11 or any other value in “else_if statement”,it will echo out 11 if it is actually equal
to 11.Again in “else statement” if value is not equal to 10 niether 11 then it will echo out “Not
equal”. In this way you can evaluate many variables at a time withhelp of “if_else if_else
statement”.
Code for if_else if Statement(Screenshot3):-
if_else if statement in php
if_else if statement(Screenshot3)
1
2
3
4
5
6
7
8
9
10
<?php
$number= 11;
if ($number==10) {
echo 'equal to ten.';
} else if ($number==11){
echo 'Equal to eleven.';
} else{
echo 'Not equal.';
}
?>
output (Screenshot4):-
if_else if statement in php
if_else if statement(Screenshot4)
In this code of “if_else statement” it will execute because $number=11 is true. It will echo out
eleven.
Code for if_else if statement(Screenshot5):-
if_else if statement in php
if_else if statement(Screenshot5)
1
2
3
4
5
6
7
8
9
10
<?php
$number= 12;
if ($number==10) {
echo 'equal to ten.';
} else if ($number==11){
echo 'Equal to eleven.';
} else{
echo 'Not equal.';
}
?>
output(Screenshot6):-
if_else if statement in php
if_else if statement(Screenshot6)
In this code of “if_elseif_else statement” it will firstly compare values inside “if statement” and
“else_if statement ” and if the comparison is false ,thus will execute “else statement” because
variable is 12 and it is not equal to 10 or 11.

Read More Extra Tutorials

No comments:

Post a Comment