News:

MyKidsDiary.in :: Capture your kids magical moment and create your Online Private Diary for your kids

Main Menu

Putting Text into Variables

Started by VelMurugan, Apr 20, 2009, 05:06 PM

Previous topic - Next topic

VelMurugan

Putting Text into Variables

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

$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:

$coats1 = 'Winter Coats';


But you can't do this:

$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:

$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.