Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP-language, conditional statements Teppo Räisänen Principal Lecturer Oulu University of Applied Sciences School of Business and Information Management.

Similar presentations


Presentation on theme: "PHP-language, conditional statements Teppo Räisänen Principal Lecturer Oulu University of Applied Sciences School of Business and Information Management."— Presentation transcript:

1 PHP-language, conditional statements Teppo Räisänen Principal Lecturer Oulu University of Applied Sciences School of Business and Information Management teppo.raisanen@oamk.fi, 050 382 6587

2 Control structures Conditional structures – If – Switch Loops – While – For Functions http://us.php.net/manual/en/language.control- structures.php http://us.php.net/manual/en/language.control- structures.php

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”; } else { if ($grade<5) { print ”B”; } else { if ($gade==5) { print ”A”; } else { 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 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/~teraisan/K1053BI/exerci se.htm http://www.oamk.fi/~teraisan/K1053BI/exerci se.htm Exercises 6 to 10 are about conditional statements


Download ppt "PHP-language, conditional statements Teppo Räisänen Principal Lecturer Oulu University of Applied Sciences School of Business and Information Management."

Similar presentations


Ads by Google