Not logged in

Your Account

Syntax Guidelines

Home/Tutorials/Syntax Guidelines

Syntax Guidelines

Content by: Steve Stewart

Posted 10 months ago with 246 views

Variable Naming:

PHP variables always begin with a dollar sign($).
Use only alphanumeric characters and underscores (a-z0-9) (_) in your variable names. Using a number to start a variable will result in an error.

$variable = 'value'; // OK
$name = 'Steve'; // OK
$var_1 = 'Variable 1'; // OK
$1_variable = 'value'; // Error

Semicolon Terminates:

A semicolon signifies that the line is terminating. If you forget the semicolon, PHP will treat all of your code as one continuous statement and could result in errors.

$var = 'Steve'; // OK
$var = 'Steve' // ERROR

php String Concatenation:

Use the period (.) to join strings or append variable data into strings.

$car_1 = 'Saab';
$car_2 = 'Mini';
echo 'My '.$car_1.' is faster than a  '.$car_2;
echo 'A '.$car_1.' is just as reliable as a '.$car_2;