iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 13, 2008
Rainbow Links
EarthWeb.com
 
May 13, 2008
MySpace Profile Page Resources
HTML Goodies
 
May 13, 2008
How to Upload Your Photos onto the Web
HTML Goodies
 
May 13, 2008
Email Marketing for MySpace Artists
HTML Goodies
 
May 13, 2008
Top Online Marketing Techniques
HTML Goodies
 
May 13, 2008
I want to create a site just like ____, is that a violation of...
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /PHP /Introduction to PHP

PHP Lesson Two - Variables 

  Views:    25044
  Votes:    4
by James N Hitz 1/23/04 Rating: 

Synopsis:

Lesson 2: takes you into the realm of PHP variables, how they are defined, concatenation and PHP operators.
Pages: firstback1 3 4 5 6 7 8 9 10 forwardlast
The Article

Variables

A variable is a smart, little hypocrite whose value changes depending on the prevailing circumstances. In it's true status, a variable is simply a named memory location. It therefore has:

  • a name
  • a value
  • a scope
  • a data type

Think of variables like a set of boxes where each box is labelled. You can put something in the box. In this case, the label is the name of the box and the value is whatever you decide to put inside the box.

When it comes to the case of PHP and computers, these little "boxes" are simply "partitions" in the computer's memory (RAM).

We will for now ignore the two later issues - scope and data type, and concentrate on name and value. Starting of course with variable names.


Defining A Variable Name

  • A variable name in PHP has a few characteristics:
  • It must start with a dollar sign ($)
  • The first character after the dollar sign ($) MUST be alphabetic (a-z A-Z) or an underscore (_) {ACII characters 127 through 255 are also valid}
  • All the other characters in the variable name must only be made of aphabetics, numbers or the underscore
  • A PHP variable is case sensitive i.e PHP, Php and php are all considered to be different because of the difference in the capitalization.
  • A PHP variable MUST NOT contain a space (or spaces).

Examples of valid PHP variables are:

$name, $_inString, $énglish

Hey! No spaces allowed?!

Yeah! No Spaces allowed. If you have long variables, you can capitalize the Initial Capitals (like $aVeryLongVariable; ), or use underscores to separate the names in the variable (like $a_very_long_variable;).

Although it is allowed to use short, cryptic variable names (like $x; for example), always avoid them because they make your code very hard to maintain and debug especially if you look at your code several months later. Don't make the variables too long either. This makes typing them an error-prone affair, and you still have to do a lot of typing too (and as it is, I am very lazy dude).

Pages: firstback1 3 4 5 6 7 8 9 10 forwardlast

Similar/related articles:


 
  Sponsors