Presentation is loading. Please wait.

Presentation is loading. Please wait.

USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.

Similar presentations


Presentation on theme: "USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on."— Presentation transcript:

1 USING CONDITIONAL CODE AMIR KHANZADA

2 Conditional Statement  Conditional statements are the set of commands used to perform different actions based on different conditions.  In PHP we have the following conditional statements: If Else Else if switch

3 If Statement  If structure is used for conditional execution of code segment.  If something is true, then do something.  Syntax: if (expr) { Statements }

4 If Statement  $d) { echo "c is bigger than d"; } ?> In the above example, only if the condition "$c>$d" is true, the message "c is bigger than d" is displayed

5 CONDITIONAL CODE If( ) { } condition // your additional code goes here //...

6 TERMINOLOGY parentheses brackets braces ()() {}{} [][]

7 CONDITIONAL CODE If( ) { } condition echo “it’s true!”; //... $a < 50$b > 20 true or false? $c == 99$c === 99$d != 100 Code block

8 EQUALITY If( $a == $b ){ // execute this code }

9 ASSIGNMENT INSTEAD OF EQUALITY $a = 5; $b = 10; If( $a = $b ){ // always true! }

10 OPERATOR WITH = =assignment ==equality ===strict equality

11 COMPARISON If( $a == $b ){ … If( $a != $b ){ … If( $a === $b ){ … If( $a !== $b ){ … If( $a > $b ){ … If( $a < $b ){ … If( $a >= $b ){ … If( $a <= $b ){ …

12 && LOGICAL AND / OR If( $a === $b $c === $d){… If( ($a > $b) && ($c > $d) ){… and or ||

13 Else Statement  If you want to execute some code if a condition is true and another code if a condition is false, use the if....else statement.  Syntax if (condition) code to be executed if condition is true; else code to be executed if condition is false;

14 Else Statement  $d) { echo "C is bigger than d"; } else { echo "D is bigger than c"; } ?> Result: D is bigger than C In the above example in the if the condition "$c>$d" is true then the message "C is bigger than D" is displayed, else the message "D is bigger than C" is displayed.


Download ppt "USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on."

Similar presentations


Ads by Google