SlideShare une entreprise Scribd logo
1  sur  7
› 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 programmes. 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 catalogue 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:
mr_coats
mrs_shoes
› But it's entirely up to you what names you give your people (variables). If you like, they could
be called this:
man_coats
woman_shoes
Or
HimCoats
HerShoes
› But because your memory is bad, it's best to give them names that help you remember what
it is they are holding for you. (There are some things your people balk at being called. You
can't begin their names with an underscore (_), or a number. But most other characters are
fine.)
› OK, 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:
mr_coats = 10
› So, the variable name comes first, then an equals sign. After the equals sign, you tell your
variable what it will be doing. Holding the number 10, in our case. (The equals sign, by the
way, is not really an equals sign. It's called an assignment operator. But don't worry about it,
at this stage. Just remember that you need the equals sign to store things in your variables.)
› However, 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:
› $mr_coats = 10
› If you miss the dollar sign out, then your people will refuse to work! But the other thing
missing is something really picky and fussy - a semi-colon. Lines of code in PHP need a semi-
colon at the end:
$mr_coats = 10;
› If you get any parse errors when you try to run your code, the first thing to check is if you've
missed the semi-colon off the end. It's very easy to do, and can be frustrating. The next thing
to check is if you've missed out a dollar sign. But back to our people (variables).
› So the man is holding ten coats. We can do the same thing with the other person (variable):
$mrs_shoes = 25;
› So, $mrs_shoes is holding a value of 25. If we then wanted to add up how many items of
clothes we have so far, we could set up a new variable (Note the dollar sign at the begining
of the new variable):
$total_clothes
› We can then add up the coats and the shoes. You add up in PHP like this:
$total_clothes = $mr_coats + $mrs_shoes;
› Remember, $mr_coats is holding a value of 10, and $mrs_shoes is holding a value of 25. If
you use a plus sign, PHP thinks you want to add up. So it will work out the total for you. The
answer will then get stored in our new variable, the one we've called $total_clothes. You can
also add up like this:
$total_clothes = 10 + 35;
› Again, PHP will see the plus sign and add the two together for you. Of course, you can add
up more than two items:
$total_clothes = 10 + 35 + 7 + 38 + 1250;
› But the idea is the same - PHP will see plus signs and then add things up. The answer is then
stored in your variable name, the one to the left of the equals sign.
› In the next part, we'll take a look at how to put text into variables.

Contenu connexe

En vedette (8)

Standards and Certifications for Emergency Managers
Standards and Certifications for Emergency ManagersStandards and Certifications for Emergency Managers
Standards and Certifications for Emergency Managers
 
Pantallazos
PantallazosPantallazos
Pantallazos
 
C.V. airport
C.V. airportC.V. airport
C.V. airport
 
Comparative analysis of algorithms classification and methods the presentatio...
Comparative analysis of algorithms classification and methods the presentatio...Comparative analysis of algorithms classification and methods the presentatio...
Comparative analysis of algorithms classification and methods the presentatio...
 
Запит в Інститут національної пам'яті
Запит в Інститут національної пам'ятіЗапит в Інститут національної пам'яті
Запит в Інститут національної пам'яті
 
Brickman Residence
Brickman ResidenceBrickman Residence
Brickman Residence
 
SC Data sheet
SC Data sheetSC Data sheet
SC Data sheet
 
Maneras de comunicar información
Maneras de comunicar informaciónManeras de comunicar información
Maneras de comunicar información
 

Dernier

Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Monica Sydney
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Monica Sydney
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
F
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
ayvbos
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
ydyuyu
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
F
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
pxcywzqs
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Monica Sydney
 

Dernier (20)

20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 
Call girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsCall girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girls
 
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
 
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime BalliaBallia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
 

What is a Variable in Php By Omar Bin Sulaiman

  • 1.
  • 2. › 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 programmes. 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 catalogue 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: mr_coats mrs_shoes
  • 3. › But it's entirely up to you what names you give your people (variables). If you like, they could be called this: man_coats woman_shoes Or HimCoats HerShoes › But because your memory is bad, it's best to give them names that help you remember what it is they are holding for you. (There are some things your people balk at being called. You can't begin their names with an underscore (_), or a number. But most other characters are fine.)
  • 4. › OK, 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: mr_coats = 10 › So, the variable name comes first, then an equals sign. After the equals sign, you tell your variable what it will be doing. Holding the number 10, in our case. (The equals sign, by the way, is not really an equals sign. It's called an assignment operator. But don't worry about it, at this stage. Just remember that you need the equals sign to store things in your variables.) › However, 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: › $mr_coats = 10
  • 5. › If you miss the dollar sign out, then your people will refuse to work! But the other thing missing is something really picky and fussy - a semi-colon. Lines of code in PHP need a semi- colon at the end: $mr_coats = 10; › If you get any parse errors when you try to run your code, the first thing to check is if you've missed the semi-colon off the end. It's very easy to do, and can be frustrating. The next thing to check is if you've missed out a dollar sign. But back to our people (variables). › So the man is holding ten coats. We can do the same thing with the other person (variable): $mrs_shoes = 25;
  • 6. › So, $mrs_shoes is holding a value of 25. If we then wanted to add up how many items of clothes we have so far, we could set up a new variable (Note the dollar sign at the begining of the new variable): $total_clothes › We can then add up the coats and the shoes. You add up in PHP like this: $total_clothes = $mr_coats + $mrs_shoes; › Remember, $mr_coats is holding a value of 10, and $mrs_shoes is holding a value of 25. If you use a plus sign, PHP thinks you want to add up. So it will work out the total for you. The answer will then get stored in our new variable, the one we've called $total_clothes. You can also add up like this: $total_clothes = 10 + 35;
  • 7. › Again, PHP will see the plus sign and add the two together for you. Of course, you can add up more than two items: $total_clothes = 10 + 35 + 7 + 38 + 1250; › But the idea is the same - PHP will see plus signs and then add things up. The answer is then stored in your variable name, the one to the left of the equals sign. › In the next part, we'll take a look at how to put text into variables.