How to Setup and use Printing Variables
A variable, is something which can hold a dynamic value. A variable is distinguished from other things because it starts with a dollar sign. For example, "$name" could be a variable which would most likely hold the name of something, someone, or someplace. Variable declaration requires the use of the "assignment operator" ("=") which will assign a value to our variable.
What you assign to a variable also requires a little thought. If you’re assigning a number to a variable, then quotes are not required. If you’re assigning a string to a variable, then quotes are required. The two basic types a variable can be are "string" and "number" and PHP understands which one you want with the presence/absence of quotes.
$name = ‘Parham’; //this will assign ‘Parham’ to the variable $name, note the quotes
$number = 12; //this will assign 12 to the variable $number, note the absence of quotes
$othernumber = ’12′; //this will assign ’12′ to the variable $number, not the presence of quotes, the variable is now interpreted as a string, not as a number
If you literally want to use quotes in your strings then they will have to be "escaped" so PHP will not get confused:
|
If you found this post useful you may also want to check these out:
|
