Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP-language, conditional statements

Similar presentations


Presentation on theme: "PHP-language, conditional statements"— Presentation transcript:

1 PHP-language, conditional statements
Jouni Juntunen Oulu University of Applied Sciences School of Business and Information Management

2 Control structures Conditional structures Loops Functions
If Switch Loops While For Functions

3 Basic syntax if (expression) { ... } else

4 Comparison operators

5 Example <? //Read value passed from HTML-form. $age=$_POST[’age’]; //Found out if user is minor or adult according to age. if ($age<18) { print ”Minor”; } else print ”Adult”; ?>

6 Nested statements <? $grade=$_POST[’grade’]; If ($grade==0) { print ”F”; } else if ($grade<3) print ”C”; if ($grade<5) print ”B”; if ($gade==5) print ”A”; print ”Not on scale”; ?>

7 Logical operations || OR && AND ! NOT

8 Example <? $grade=$_POST[’grade’]; //If grade is not between 0 and 5 it is //not on scale. If ($grade<0 || $grade>5) { print ”Not on scale”; } ?>

9 Switch Sometimes you can replace multiple if-statements with switch statement Also logical and comparison operators are allowed

10 Exercises http://www.oamk.fi/~jjuntune/php/exercises.php
Exercises 6 to 10 are about conditional statements


Download ppt "PHP-language, conditional statements"

Similar presentations


Ads by Google