Skip to content

Instantly share code, notes, and snippets.

@iods
Created March 18, 2017 03:17
Show Gist options
  • Save iods/5a7465979da7b0b840f9acc16454bb40 to your computer and use it in GitHub Desktop.
Save iods/5a7465979da7b0b840f9acc16454bb40 to your computer and use it in GitHub Desktop.
PHP Control Structures

Control Structures in PHP

In programming, a problem specific to decision making and the flow of execution can be broken down into three specific types of control structures. These are:

  • Sequential Execution
  • Loops (while, do/while, for, etc.)
  • Two-Way Decisions (if, if/else, switch, etc.)

Examples

The if/else Statement

The most commonly used conditional statement is the if/else statement.

if ($expression)
{
  // statement
}
else 
{
  // statement 
}

It is important to remember a few things about this statement:

  • The else clause is optional
  • Best use is to make the expression boolean logic, evaluating to either True or False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment