Simply put, a variable is a symbol that can store different values at different times. For
example, suppose you create a Web-based calculator capable of performing mathematical
tasks. Of course, the user will want to plug in values of his choosing; therefore,
the program must be able to dynamically store those values and perform calculations
accordingly. At the same time, the programmer requires a user-friendly means for
referring to these value-holders within the application. The variable accomplishes
both tasks.
Table 3-3. Valid and Invalid Identifiers
Valid Invalid
my_function This&that
Size !counter
_someword 4ward
74 CHAPTER 3 ?– PHP B ASICS
Given the importance of this programming concept, it would be wise to explicitly
lay the groundwork as to how variables are declared and manipulated. In this section,
these rules are examined in detail.
?– Note A variable is a named memory location that contains data and may be manipulated throughout
the execution of the program.
Variable Declaration
A variable always begins with a dollar sign, $, which is then followed by the variable
name. Variable names follow the same naming rules as identifiers. That is, a variable
name can begin with either a letter or an underscore and can consist of letters, underscores,
numbers, or other ASCII characters ranging from 127 through 255. The following
are all valid variables:
??? $color
??? $operating_system
??? $_some_variable
??? $model
Note that variables are case sensitive.
Pages:
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159