Algoritma & Pemrograman 1 Achmad Fitro The Power of PowerPoint – thepopp.com Chapter 3
PHP Conditional 2 if statement - executes some code if one condition is true if...else statement - executes some code if a condition is true and another code if that condition is false if...elseif....else statement - executes different codes for more than two conditions switch statement - selects one of many blocks of code to be executed In PHP we have the following conditional statements: Very often when you write code, you want to perform different actions for different conditions.. You can use conditional statements in your code to do this
If Statement if (condition) { code to be executed if condition is true; } 3
If else Statement if (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; } 4
If elseif else Statement if (condition) { code to be executed if this condition is true; } elseif (condition) { code to be executed if this condition is true; } else { code to be executed if all conditions are false; } 5
Switch Statement switch (n) { case label1: code to be executed if n=label1; break; case label2: code to be executed if n=label2; break; case label3: code to be executed if n=label3; break; default: code to be executed if n is different from all labels; } 6
Thank You for Watching! Any Questions?