Tuesday, 31 July 2012

PHP control statement and logical operator example

This tutorial is not like other PHP tutorial. To understand this tutorial you need to have enough knowledge on PHP control structure such as if, else, if….else etc and PHP logical operators. It gives you some capability to solve complex problem. Real life problem is very complex. For example, if Rahim age is between fifteen and sixteen then we call Rahim is teenage boy. So guys let’s start to write the problem in PHP code.
<? Php
$ Up_years = 20;
$ Low_years = 15;
If ($ up_years <20&& $ low_years> 15)
echo “Rahim is teenage boy”;
?>

We now try to write the problem in another way, if Rahim age is not between fifteen and twenty and also is not between twenty and hundred then we call Rahim is a little boy.
<? Php
If (($ low_years< 15&& up_years >20) && ($ low_years> 20 && $ up_years <100))
echo “Rahim is a little boy”;
?>

If Rahim age is fifteen or twenty then our program print “Now you are teenage”. We can solve it using php logical or operator.
<? Php
If (($ low_years == 15) | | ($ up_years == 20))
echo "Now you are teenage";
?>
It is very enjoyable for us to solve this type of problem. My suggestion is trying to solve different type of problem using logic. I hope you will get better results in PHP programming than others.

No comments:

Post a Comment