Star Hoster
Photoshop Tutorials
Anonymous Web Surfing
Funny Jokes
Myspace Friends
Open Treasure Chest
Building in Paradise


November 30, 2005

PHP Variables

Filed under: Intro PHP Tutorials — phpdeveloper @ 4:50 am

Variables in PHP

In this Tutorial we will learn about Variables and Data Types in PHP.

What is a Variable?

Variables are nothing but identifiers to the memory location to store data. We can create any number of variables. In PHP all the variables begin with a dollar sign “$” and the value can be assigned using the “=” operator as shown below:

Example:

$Name, $address, $salary

$Name = “Uday”;

$Age = 25;

Important thing in PHP is that all the statements must end with a semicolon “;” which is called termination mark. In PHP we don’t have to specify the variable type, as it takes the data type of the assigned value. From the above example we understand that ‘$Name’ is of Data type String (Group of characters) and ‘$Age’ is of type Numeric.

Rules in Variable Naming:

PHP has no limit on the length of variable name as in the case of other programming languages. The variable name must start with a letter or underscore. The variable name must be a combination of letters, numbers and underscores. Other characters such as *, +, #, @, ?, / are not allowed and causes error if used. You cannot use reserve words (language functions and statements) as a variable.

Case-sensitive
Variables in PHP are case-sensitive, so that two identically spell variables with different casing will result in 2 variables instead of one.

$myvar = “First Variable”
$Myvar = “Second Variable”

In PHP $myvar and $Myvar are two different variables. Normally you should have your own naming convention when you are doing development based on some standards, so that all your variables will follow certain patterns.

Some naming conventions could be starting with Capital letter, using underscores, or capitalizing all words within a variable.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.