Table of Contents



Introduction

PHP is a strightforward programming language with roots in C and Perl . To get started with learning PHP, we need to first learn a few basic rules on its syntax.

Semicolons

All PHP statements end with a semicolon.

Example

PHP statements must end with semicolon.

1<?php
2    $x = 10;
3    $x += 10;
4    echo $x;
5?>
20

The $ Symbol

In PHP, you must place a $ in front of all variables. This is required to make the PHP parser faster, as it instantly knows whenever it comes across a PHP variable. Refer to the previous example where the variable x is prefixed by the $ symbol.

ADVERTISEMENT



Case Sensitivity

In PHP,

  • Keywords are not case-sensitive.
  • Variable names are case-sensitive.

Keywords (e.g. if, else, do, for, echo, etc.), classes, functions, and user-defined functions are not case-sensitive.

Example

PHP keywords are not case-sensitive.

1<?php
2    for ($count = 1 ; $count <= 5 ; ++$count)
3        echo "$count x 3 = " . $count * 3 . "<br>";
4?>
1 x 3 = 3
2 x 3 = 6
3 x 3 = 9
4 x 3 = 12
5 x 3 = 15

In the following example, the for and echo keywords are not lowercase. But the code works fine and output is identical.

1<?php
2    FOR ($count = 1 ; $count <= 5 ; ++$count)
3        Echo "$count x 3 = " . $count * 3 . "<br>";
4?>
1 x 3 = 3
2 x 3 = 6
3 x 3 = 9
4 x 3 = 12
5 x 3 = 15

However, all variable names are case-sensitive.

Example

PHP variable are case-sensitive.

1<?php
2    $rx = 20;
3    echo "The value is $rx. <BR>";
4    echo "The value is $Rx. <BR>";
5    echo "The value is $RX. <BR>";
6?>
The value is 20.

Warning: Undefined variable $Rx in C:\xampp\htdocs\php\intro1.php on line 27
The value is .

Warning: Undefined variable $RX in C:\xampp\htdocs\php\intro1.php on line 28
The value is .

We see that only the first echo statement prints the output correctly since only the lowercase variable rx is assigned a value and variable names are case-sensitive.

Note

The <BR> tag is used to insert a single line break in a text.