PHP Control Structures and Conditional Statement- Tutorialpath

In simple terms, a control structure allows you to control the flow of code execution in your application. Generally, a program is executed sequentially, line by line, and a control structure allows you to alter that flow, usually depending on certain conditions.

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.

Conditional Statement

  • Conditional statement is used for making condition based program.
  • Conditional Statements allow you to branch the path of execution in a script based on whether a single, or multiple conditions.
  1. If
  2. If- Else
  3. Nested If- Else
  4. Switch

1.  If :- if x and then do y (if condition is true then print some statement).

Example:

Output:

2.  If- Else :- If x and then do y otherwise do Z ( if condition is true then print some statement and otherwise print some different statement).

Example:

Output:

3.  Nested If-else:- More than one condition is used.

Example:

Output:

4. Switch Case:- Use the switch statement to select one of many blocks of code to be execute.

Example:

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *

//graizoah.com/afu.php?zoneid=3461279