Archive for Variables

Naming Variables

Variable names or identifiers should be very descriptive. I have seen scripts
where all the variables were named $var1, $var1, $var2, and so on. It may

seem straightforward to name variables like this, but two years from now
when you come back to the script, it will take forever to figure out what
information is in each variable. PHP won’t care or get confused, but humans
trying to follow the script will have a hard time. Make your scripts much
easier to understand by using descriptive variable names like $firstName,
$directory_name, or $DateOfBirth. Read the rest of this entry »

Leave a Comment

Using Variables in PHP Scripts

Variables are containers that hold information. First, you give a variable a
name, and then you can store information in it. For example, you could
name a variable $age and store the number 21 in it. After you store information
in a variable, you can use that variable later in the script. Read the rest of this entry »

Leave a Comment

Displaying variable values

The quickest way to display the value stored in a variable is with the print_r
statement. You can output the value of a variable as in the following statements: Read the rest of this entry »

Leave a Comment

Creating variables

Variables can hold either numbers or strings of characters. A variable can
exist or not exist and can hold information or not hold information; these are
two separate ideas. Even if a variable doesn’t currently contain any information,
it still can exist, just as a drawer exists even when it is empty. Of course,
if a variable contains information, it has to exist. Read the rest of this entry »

Leave a Comment

Removing Variables

You can also remove information from a variable. You can use the following
statement: Read the rest of this entry »

Leave a Comment

Using Variable Variables

PHP allows you to use dynamic variable names, called variable variables. You
can name a variable by using the value stored in another variable. That is, one
variable contains the name of another variable. For example, suppose you want
to construct a variable named $city with the value Los Angeles. You can use
the following statement: Read the rest of this entry »

Leave a Comment