Logo Your Web Hosting Solution
Line
PHP Documentation
Introduction
Variables
Using Forms
Sending Email
MySQL Databases
Tutorials Index
Home Page
PHP Tutorial - Variables

A variable holds a value. For an easy example :

x = 1 + 2

In this case, our variable x holds a value of 3.

PHP variables start with a dollar sign ($) and can be modified at any time. Variables are also used to pass data from one page to the next (see using forms).

Sample variable manipulation

<?php
$name = "Barney";
$color = "purple";
print ("My name is $name, I like the color $color.<BR>");
$color = "blue";
print ("My name is $name, I like the color $color.<BR>");
?>

Two variables are defined, $name and $color. The values these two hold are shown, in a phrase.

Next, the value of variable $color is modified and the values are shown again. Output would look as below.

Output

My name is Barney, I like the color purple.
My name is Barney, I like the color blue.

Note that PHP variable names are case sensitive and must start with a letter. Only numbers, letter and the underscore character are valid for variable names.

PHP support is enabled on all web site hosting plans.

Top Of Page 
Line
Copyright© 1996 - 2017 Clockwatchers, Inc.