Basics

Statement

PHP

 

Escaping to PHP

PHP 5
<?php
  
  print('Hello World!');

?>

All PHP code should be written in between <?php ... ?> tags in order to be distinguished from other elements on the page.

There are other syntaxes for specifying PHP code sections like <? ... ?> and <% ... %> but they need to be configured on the PHP parser engine.

We won't include Escaping Tags in our following examples for readability purposes.

 

Escaping to PHP

PHP 5
<?= $a ?>

This is a short way of writing <?php echo $a; ?>.

 

Statement

PHP 5
print('statement 1');
print('statement 2');
//...

Statements are similar to sentences in natural languages.

Statement is a complete unit of execution.

Statements should be terminated with a semicolon (;).

 

Whitespaces

PHP 5
print (  "statement 1" );

print
  ("statement 2");

print(
  "statement 3"
);

PHP ignores Whitespaces.

Space, Tab, Line-breaks are all considered whitespace.

You can use this as a tool to make your code more readable.

 

Case Sensitivity

PHP 5
$age = 12;

print($age);  // 12
Print($age);  // 12
print($Age);  // error

PHP is a Partially Case Sensitive language.

It is acting case-insensitive for example on Function names but case-sensitive on Variable names.

It is highly recommended to not rely on the case-insensitivity part of the PHP when writing your code.

 

Blocks

PHP 5
{
  print('statement 1');
  print('statement 2');
}

Block is used to group zero or more statements.

Block is indicated by a pair of curly brackets.

Block can be prefixed or postfixed by other keywords like if, while to run them in a specific way.

 

Empty Statement

PHP 5
;

An empty statement is used to provide no statement, although PHP syntax would expect one.

For example, if you want to run a for loop without a block.