PHP 5 Variables

PHP 5 Variables

PHP 5 Variables

Variables are “containers” for storing information.

Creating (Declaring) PHP Variables

In PHP, a variable starts with the $ sign, followed by the name of the variable:

Example

<?php
$txt = “Hello world!”;
$x = 5;
$y = 10.5;
?>

Output Variables

The PHP echo statement is often used to output data to the screen.

The following example will show how to output text and a variable:

Example

<?php
$txt = “mkitweb.com”;
echo “I love $txt!”;
?>

The following example will produce the same output as the example above:

Example

<?php
$txt = “mkitweb.com”;
echo “I love ” . $txt . “!”;
?>

The following example will output the sum of two variables:

Example

<?php
$x = 5;
$y = 4;
echo $x + $y;
?>
Please follow and like us:

Post Author: aamirkhan

Leave a Reply

Your email address will not be published. Required fields are marked *