PHP Variables
A variable is used to store values so that it can used in any time.
A variable inside a PHP block of codes should looks like:
<?php
$var = Value;
?>
A typical example of PHP variable placed in HTML document should look like:
<html>
<head>
<title>PHP Tutorial</title>
</head>
<body>
<h1>PHP Variables Example</h1>
<?php
$shop = "osCommerce Online Shop";
echo 'The value of $shop variable is: ' . $shop;
?>
</body>
</html>
The output of the above PHP variables example should look like:
PHP Variables Example
The value of $shop variable is: osCommerce Online Shop
Note:
- We used 'The value of $shop variable is: ', not "The value of $shop variable is: ". Because we want to print out the $shop wording.
- We used the "dot" to join 'The value of $shop variable is: ' and $shop. The 'dot' is called PHP Concatenation operator and will be disussed in next PHP tutorial.