PHP and MySQL Programming/Syntax Overview



 * Enclose PHP code
 * Embedded in normal HTML code
 * Within PHP tags, statements are separated by a ; (generally also followed by a new line).

Example:

//
Comments out one line

Example:

Example:

#
Same function as //

/* (text) */
Comments out everything between the /* and the */

Example:

Variables
Variables in PHP are denoted by the $ prefix.

Example:

PHP supports dynamic variables.

Example:

PHP variables do not have to be declared ahead of time, nor do they require a type definition. PHP handles all data type conversions.


 * Example:

PHP supports Boolean variables, which can be assigned either a one or a zero, or a true or false.

Example:

Helpful Definitions:

 * Equal vs Identical
 * Equal: values are equal in value, but may be of differing types. Uses == comparison operator.  E.g. false is equal to 0.
 * Identical: values are equal in value and of the same type. Uses === comparison operator.  E.g. false is identical only to false, it is not identical to 0.

Arithmetic Operators
Example:

Assignment Operators
Example:

Comparison Operators
Example:

Concatenation
Example:

Arrays
PHP supports both numerically indexed arrays as well as associative arrays.

Example:

If ... else statement
Example:

Switch statement
Example:

For statement
Example:

Foreach statement
Example:

While statement
Example:

Do ... while statement
Example:

Functions
Example:

Classes
Example:

As of PHP 5.3.3, functions with the same name as the class will no longer act as a constructor. Versions prior to 5.3.3 the  line could be replaced with   to achieve the same effect.