if_ else if Statement in php |
Code for if_else if statement(Screenshot1):-
If_else If Statement Screenshot1 |
<?php $number= 10; if ($number==10) { echo 'equal to ten.'; } else if ($number==11){ echo 'Equal to eleven.'; } else{ echo 'Not equal.'; } ?>
output (Screenshot2):-
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 “if statement”, 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 with help of “if_else if_else
statement”.
Code for if_else if Statement(Screenshot3):-
if_else if Statement (Screenshot3) |
<?php $number= 11; if ($number==10) { echo 'equal to ten.'; } else if ($number==11){ echo 'Equal to eleven.'; } else{ echo 'Not equal.'; } ?>
output (Screenshot4):-
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):-
Screenshot5 |
<?php $number= 12; if ($number==10) { echo 'equal to ten.'; } else if ($number==11){ echo 'Equal to eleven.'; } else{ echo 'Not equal.'; } ?>
output(Screenshot6):-
Screenshot6 |
In this code of “if_else if_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.
No comments:
Post a Comment
Thanks For Comment Will get you Soon..