Control statements in php ppt

Presentation on theme: "PHP CONDITIONAL STATEMENTS"— Presentation transcript:

1 PHP CONDITIONAL STATEMENTS
Padasalai PHP CONDITIONAL STATEMENTS CHAPTER -6 MOHAMED FAKRUDEEN, PGT-COMPUTER SCIENCE SHAMROCK MATRIC. HR. SEC. SCHOOL. MOGAPPAIR, CHENNAI-107

2 Learning Objectives To understand the importance of conditional statement To know different type of conditional statements in PHP To know the basic fundamental logic creation using conditional statement

3 PHP conditional statement
Conditional statements are useful for writing decision making logics. It is most important feature of many programming languages , including PHP. They are implemented by the following types: if statement if…else statement if…elseif….else statement switch statement

4 If statement in PHP If statement executes a statement or a group of statements if a specific condition is satisfied as per the user expectation

5 SYNTAX: if[ condition ] { Execute statement[s] if condition is true; }

6 Example:

7 If else statement in PHP
If statement executes a statement or a group of statement if a specific condition is satisfied by the user expectation. When the condition gets false [fail] the block is executed.

8 SYNTAX: If [condition] { Execute statement [s]if condition is true; }
Else Execute statement[s] if condition is false;

9 Example:

10 If elseif else statement in PHP:
If - elseif- else statement is a combination of if-else statement. More than one statement can execute the condition based on user needs.

11 SYNTAX If[ 1st condition] { Execute statement[s ]if condition is true;
} elseif[ 2nd condition ] Execute statement[s] if 2nd condition is true; Else Execute statement[s] if both conditions are false;

12 Example:

13 Switch case: The switch statement is used to perform different actions based on different conditions.

14 SYNTAX: switch [n] { case label 1: code to be executed if n=label 1;
break; case label 2: code to be executed if n=label 2; case label 3: code to be executed if n=label 3; default: code to be executed if n is different from all labels; }

15 EXAMPLE:

16 POINTS TO REMEMBER The if statement contains boolean expression inside brackets followed by a single or multi line code block. if –else Statement also provides for a second part to the if statement , that is else. The else statement must follow if or else if statement. else if statement The ‘if’ statement can also follow an “else” statement, if you want to check for another condition in the else part.

17 NEXT TOPIC: LOOPING STRUCTURE

Just for you: FREE 60-day trial to the world’s largest digital library.

The SlideShare family just got bigger. Enjoy access to millions of ebooks, audiobooks, magazines, and more from Scribd.

Read free for 60 days

Cancel anytime.

What are control statements in PHP?

Control statements are conditional statements that execute a block of statements if the condition is correct. The statement inside the conditional block will not execute until the condition is satisfied.

What are control statements?

Control statements are the statements that change the flow of execution of statements. For example, If, If-else, Switch-Case, while-do statements.

What are control statements types?

There are three types of control statements: Conditional/Selection statements. Iteration/Loop statements. Jump statements.

What is PHP control structure?

Control structures are core features of the PHP language that allow your script to respond differently to different inputs or situations. This could allow your script to give different responses based on user input, file contents, or some other data.

Chủ Đề