![]() |
What is a Variable?
Getting Started With Variables A variable is just a storage area. You put things into your storage areas (variables) so that you can use and manipulate them in your script. Things you'll want to store are numbers and text. If you're ok with the idea of variables, then you can move on. If not, think of them like this. Suppose you want to catalog your clothing collection. You enlist two people to help you, a man and a woman. These two people are going to be your storage areas. They are going to hold things for you, while you tally up what you own. The man and the woman, then, are variables. You count how many coats you have, and then give these to the man. You count how many shoes you have, and give these to the woman. Unfortunately, you have a bad memory. The question is, which one of your people (variables) holds the coats and which one holds the shoes? To help you remember, you can give your people names! You could call them something like this: Code:
mr_coatsCode:
man_coatsOK, so your people (variables) now have name. But it's no good just giving them a name. They are going to be doing some work for you, so you need to tell them what they will be doing. The man is going to be holding the coats. But we can specify how many coats he will be holding. If you have ten coats to give him, then you do the "telling" like this: Code:
mr_coats = 10However, you're learning PHP, so there's something missing. Two things, actually. First, your people (variables) need a dollar sign at the beginning (people are like that). So it would be this: PHP Code:
PHP Code:
So the man is holding ten coats. We can do the same thing with the other person (variable): PHP Code:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
In the next part, we'll take a look at how to put text into variables. NEXT PART POSTED DOWN! |
Great beginner tutorial!
|
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:
PHP Code:
PHP Code:
We can store other text in the same way: PHP Code:
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. |
<Reserve this post for tutorial>
|
<Reserve this post for tutorial>2
|
Reserve this for a tutorial!
|
nice tutorial ^^ did you write it yourself?
|
ty tanax yes.
|
| All times are GMT. The time now is 12:35 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0