PHP Commands




PHP Tutorial > Syntax

This pages lists common PHP commands and their respective syntax. To view details on each command, please click on the link; to learn PHP from the beginning, please go to the PHP Tutorial homepage.

DO ... WHILE

DO {
  [code to execute]
} WHILE (conditional statement)

ELSEIF

IF (conditional statement 1) {
  [code if condition statement 1 is true]
}
ELSEIF (conditional statement 2) {
  [code if condition statement 2 is true]
}
ELSE {
  [code if neither statement is true]
}

FOR Loop

FOR (expression 1, expression 2, expression 3)
{
  [code to execute]
}

FOREACH Loop

FOREACH ($array_variable as $value)
{
  [code to execute]
}
or
FOREACH ($array_variable as $key => $value)
{
  [code to execute]
}

IF ELSE

IF (conditional statement) {
  [code if condition is true]
}
ELSE {
  [code if condition is false]
}

Include

INCLUDE ("external_file_name");

SWITCH ($variable) {
CASE 'value 1':
  [code to execute when $variable = 'value 1']
  break;
CASE 'value 2':
  [code to execute when $variable = 'value 2']
  break;
CASE 'value 3':
...
DEFAULT:
  [code to execute when none of the CASE values matches $variable']
}

WHILE Loop

WHILE (expression)
{
  [code to execute]
}

Next: Resources



Copyright © 2014   1keydata.com  All Rights Reserved.  Privacy Policy