About us Privacy Disclaimer Contact us
FAQ Help Advertising Feedback
Home Sitemap Search Donate us

  Home > Computer & I'net > Variables...

   Browse by title articles:
   What is hot:

Escape Characters

Operators

Print/Echo

Variables

Numbers - Formatting

Numbers - Math

Storage and re-use of images using PHP/GD - Part I
Arrays Intro
Bad Web Design: Looong Pages
Every Search Engine Robot Needs Validation
Prev articles12345 6 789101112Next articles



Variables


Computer & I'net articlesVariables

by David Stanley    



Variables are containers. Think of an ordinary box that you put stuff into. That box may have a label on it so you remember what is inside of it. Variables are boxes that you put data information into. They are labeled with names.

Once you have some information in variables, it can be sorted, organized, manipulated, and so forth.

A variable name starts with a dollar $ symbol. After that you can use any combination of higher case letters A-Z, lower case letters a-z, or the underscore character _. Spaces are not allowed.

Variable names are CaSe SeNsItIvE. If you are referring to a variable in your coding, make sure the name matches exactly.
$MyVariableName is different from $myvariablename.

Variable names should be easy to understand. Give some thought into the names.
$fn or $FirstName or $first_name
Which one looks more easier to understand and remember?

There are three types of variables. Numbers, Strings, and Arrays.

Number Variables may contain integers (regular positive or negative numbers) or floating-point (decimal) numbers. No fractions, letters, or extra decimals allowed.

$integer_example = 5;
$floating_point_example = 365.25;

String Variables are word variables. They may contain number information and other variables. The values of string variables are contained within single quotes ' ' or double quotes " " depending on how you want to use them.

$string_example_1 = "This is a test.";
$string_example_2 = 'This is another test.';
$string_example_3 = "5";
$string_example_4 = "The value is $integer_example.";
$string_example_5 = 'The value is $integer_example.';

The difference between single and double quotes is : Single quotes will print out the exact value of the string as is. Double quotes will transfer variable values into place before printing.

echo "$string_example_4 <br />";
echo "$string_example_5";

Outcome :
The value is 5.
The value is $integer_example.

Arrays are groups of variables. These will be discussed in more detail on their own page.




-----------------
Article by David Stanley. Visit his site http://www.htmlite.com. Reprinted with permission.





Cost Spreading




  Disclaimer | Privacy | Terms of useCopyright © 2004 Nice2know.com