Difference between revisions of "Variables in PHP"
From OdleWiki
m (→Basics) |
|||
Line 6: | Line 6: | ||
Variables in PHP: | Variables in PHP: | ||
− | #always begin with a dollar sign ($) | + | #always begin with a dollar sign (<span class="mono">$</span>) |
− | #start with a letter or underscore (_) | + | #start with a letter or underscore (<span class="mono">_</span>) |
#may contain any number of letters, numbers, and underscores | #may contain any number of letters, numbers, and underscores | ||
#are case-sensitive | #are case-sensitive | ||
Line 29: | Line 29: | ||
<pre>var$</pre> (Variables names must '''begin''' with a dollar sign.) | <pre>var$</pre> (Variables names must '''begin''' with a dollar sign.) | ||
− | |||
==Types of Variables== | ==Types of Variables== |
Revision as of 23:22, 10 December 2013
Contents
Basics
Variables in PHP:
- always begin with a dollar sign ($)
- start with a letter or underscore (_)
- may contain any number of letters, numbers, and underscores
- are case-sensitive
Examples of Acceptable Variable Names
$var<br /> $_var<br /> $_Var<br /> >$VAR<br /> $VAR_001<br />
This is not a comprehensive list, merely examples.
Examples of Unacceptable Variable Names
$var*
(Variable names may only contain letters, numbers, and underscores.)
$var #1
(Variable names may not contain # or spaces.)
var$
(Variables names must begin with a dollar sign.)
Types of Variables
Assigning Values to Variables
To assign a value to a variable, use a single equal sign (=)
$var = "Hello, world."