Variables are temporary storage containers. In PHP, a variable can contain any type of data, such as, for example, strings, integers, floating-point numbers, objects and arrays. PHP is loosely typed, meaning that it will implicitly change the type of a variable as needed, depending on the operation being performed on its value. This contrasts with strongly typed languages, like C and Java,where variables can only contain one type of data throughout their existence.
PHP variables are identified by a dollar sign $, followed by an identifier name. Variables must be named using only letters (a-z, A-Z), numbers and the underscore character; their namesmust start with either a letter or an underscore, and are one of only two identifier types in PHP that are case-sensitive (the other is constants, discussed below). Here are a few examples:
* $name = 'valid'; // Valid name
* $_name = 'valid'; // Valid name
* $1name = 'invalid'; // Invalid name, starts with a number
Variable of Variables
In PHP, it is also possible to create so-called variable variables. That is a variable whose name is contained in another variable. For example:
PHP variables are identified by a dollar sign $, followed by an identifier name. Variables must be named using only letters (a-z, A-Z), numbers and the underscore character; their namesmust start with either a letter or an underscore, and are one of only two identifier types in PHP that are case-sensitive (the other is constants, discussed below). Here are a few examples:
* $name = 'valid'; // Valid name
* $_name = 'valid'; // Valid name
* $1name = 'invalid'; // Invalid name, starts with a number
Variable of Variables
In PHP, it is also possible to create so-called variable variables. That is a variable whose name is contained in another variable. For example:
No comments:
Post a Comment