PHP Statements - Introduction and Examples


Tutorial Topic:

PHP statements are used to calculate and output data, which is then presented to the user by a web browser. All PHP statements end with:



The following PHP statement saves the text Hello World to a PHP Variable $hi. Every piece of text in PHP statements need to be wrapped in ' ' or " ".

$hi = 'Hello World';

The following php statement outputs the value of variable $hi. Variables should be used without ' ' or " " in PHP statements.

echo $hi;

Text and variables can also be combined in a single PHP statement like

echo 'The value of variable is ' . $hi . '. I saved it for testing';

In this example, variable and text statements are combined by the notation (.).

  • Text: 'The value of variable is '
  • Variable: $hi
  • Text: '. I saved it for testing.'

The output of the above PHP statement will be:

The value of variable is Hello World. I saved it for testing.