valid n invalid Variabels

Valid variabels

a : Single-letter variables are good for temporary purposes, such as loop counters.

firstName : Variables that look like words help make your scripts easier to understand.

_1 : Traditionally, variables that begin with an underscore have special meaning to the local namespace.

inValid variabels

1 : The first character following the dollar sign may not be a number.

7Lucky : The first character following the dollar sign may not be a number. Use Lucky7 instead.

~password : ~ is not an alpha character and may not be used in variable names.

Last!Visit : ! is not an alpha character and may not be used in variable names. Use LastVisit or last_visit instead.

Compute-Mean : – is not an alpha character and may not be used in variable names. Use Compute_Mean instead.

The equal sign (=) is used to set the value of a variable. This is called the assignment operator. On the left side of the assignment operator is a variable that will receive a value. On the right side is an expression, which could be a simple string constant or a complex combination of operators, variables, and constants. The simplest form of assignment is from a constant expression. This could be a number or a string surrounded by quotes.

Sample of Variables Assignments
String Constants Integer Constants Double Constants

$myString = “leon”; $myInteger = 1; $myDouble = 123.456;
$myString = “\n”; $myInteger = -256; $myDouble = -98.76e5;

Most compiled languages, such as C or C++, require you to declare every variable along with the type of value that it will contain, and they require every code piece to state in advance what kind of values it is designed to work with. Most interpreted languages, such as PHP, allow variables to store any type of value and allow code units to work with any type of value. PHP doesn’t even require you to explicitly declare a variable before you use it. Instead, the first time you assign a variable with some value, it is created. This simplifies development and helps you produce and maintain working programs more quickly. It also can lead to bugs when you use a variable before initializing it.

Variables in PHP don’t have designated types. Instead, the type of the variable is considered to be the type of the value that it contains. The type of value that variables contain may be changed at any time. For example, assigning an integer to a variable that previously held a string converts the variable to an integer. This is in contrast to C, where each variable has a designated type. Assigning a value to a variable of a different type will make C attempt to convert the value so that it fits the variable.

How to use variabel

//create variable
$result = 2 + 5;

//create another variable
$doubleResult = $result * 2.001;

//print the second variable

As mentioned earlier, double-quoted strings and HERE docs may contain embedded variables. You may write a variable inside a string surrounded by double quotes, and its value appears in its place. This even works with arrays and objects. Listing below is an example of this technique. Notice that the name variable appears within a print statement between double quotes.

$name = “Zeev”;

//Greet Zeev
print(“Hello, $name!\n”);

//Greet Zeev again
print <<< EOD
Hello again, $name!
How is it going?


About asyhadione

jusT an Ordinary man

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: