Who's Online
We have 7 guests onlineBreadcrumbs
| Variables |
PHP Variables
If you have never had any programming, Algebra, or scripting experience, then the concept of variables might be a new concept to you. A detailed explanation of variables is beyond the scope of this tutorial, but we've included a refresher crash course to guide you. A variable is a means of storing a value, such as text string "Hello World!" or the integer value 4. A variable can then be reused throughout your code, instead of having to type out the actual value over and over again.
In PHP you define a variable with the following form: $variable_name = Value;
If you forget that dollar sign at the beginning, it will not work. This is a common mistake for new PHP programmers!
Note: Also, variable names are case-sensitive, so use the exact same capitalization when using a variable. The variables $a_number and $A_number are different variables in PHP's eyes.
There are a few rules that you need to follow when choosing a name for your PHP variables.
A variable is used in programming to represent another value. In PHP variables all start with a dollar sign ($). They can be set to a string or a numeric value. Code: <?php
You will notice that string values are contained with quotations [""] while numeric values are not. Instaed of just a static number, you can also set a variable equal to an equation. Here are some examples: Code: <?php
We can combine values using a period [.] This will literally mash the values together. Here are some examples:
Code: <?php
This is different than just echoing both variables as a new variable is actually created from the other variables.
Another thing you can do is make a variable from a string by using {} symbols. So, by using this method you could pass a string from one page to another, and use that string to pull the information from a variable of the same name. Here is an example:
Code: <?php
|