View Single Post
Old 07-01-2008, 03:31 PM   #3 (permalink)
codefreek
Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 450
Thanks: 228
codefreek is on a distinguished road
Default Putting Text into Variables

in the previous section, you saw how to put numbers into variables. But you can also put text into your variables. Suppose you want to know something about the coats you own. Are they Winter coats? Jackets? Summer coats? You decide to catalog this, as well. You can put direct text into your variables. You do it in a similar way to storing numbers:

PHP Code:
$coats1 "Winter Coats"
Again, our variable name starts with a dollar sign ($). We've then given it the name coats1. The equals sign follows the variable name. After the equals sign, however, we have direct text - Winter Coats. But notice the double quotation marks around our text. If you don't surround your direct text with quotation marks, then you'll get errors. You can, however, use single quotes instead of double quotes. So you can do this:

PHP Code:
$coats1 'Winter Coats'
But you can't do this:

PHP Code:
$coats1 Winter Coats"; 
In the above line, we've started with a single quote and ended with a double quote. This will get you an error.

We can store other text in the same way:


PHP Code:
$coats2 "Jackets";
$coats3 "Summer Coats"
The direct text will then get stored in the variable to the left of the equals sign.

So, to recap, variables are storage areas. You use these storage areas to manipulate things like text and numbers. You'll be using variables a lot, and on the next few pages you'll see how they work in practice.
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.

Last edited by codefreek : 07-01-2008 at 08:14 PM.
codefreek is online now  
Reply With Quote
The Following User Says Thank You to codefreek For This Useful Post:
nathanurag (07-02-2008)