There are eight types of variables in the 1.PHP:
<1> Scalar types:
Boolean (Boolean)
Integer (integer type)
Float (floating point type, also "double")
String (String)
<2> Composite types:
Array (arrays)
Object (Objects)
<3> Special types:
Resource (resources)
Null
ps:php variable type do not declare, PHP will be based on the context of the program run, automatically determine its type, is not very smart? It's too much for the force.
If you want to see the values and similarities of an expression, you can use the function var_dump ().
(1). Boolean (Boolean)
Only two values are true or false, case insensitive, and non-0 is true,0 is false.
Boolean (Boolean) is often used for process control to make conditional judgments.
Example:
[PHP] <?php $b =true; if ($b = = True) { echo ' $b is true '; } ? >
2.integer (integral type)
Integer values can be specified in decimal, hexadecimal, or octal notation
Example:
<?php$b = 1234; Decimal number $b =-123; A negative number $b = 0123; Octal number (equal to decimal) $b = 0x1A; Hexadecimal number (equals 26 in decimal)
?>
3.float (floating point type, also "double")
Floating-point numbers (also known as floating-point numbers, double-precision, or real numbers) can be defined with any of the following syntax:
Example:
[PHP] <?php $b = 1.334; $b = 1.3e3; $b = 8E-10; ? >
(4) string (string)
There are three ways to define a string: Single quotation marks, double quotes, and delimiters.
For example:
[PHP] <?php //single quotation mark definition string $a = ' aaa '; The double quotation mark defines the string $b = "BBB"; Delimiter definition string $c = <<<eof ccccccccc eof;//top start writing, front cannot leave blank echo $a; echo "<br>"; echo $b; echo "<br>"; echo $c; ? >
Variable resolution:
Single quotation marks: If you include variables in the definition content, directly output the variable name instead of the content.
Double quotation marks: If the definition includes variables, the content is output directly.
Delimiter: Outputs content directly if the variable is included in the definition content.
In double quotation marks and delimiters, you can specify the range of variables with {}.
[PHP] <?php $temps = "123"; $TEMPSS = "1234"; $b = "bbb{$temps}s"; echo $b; ? >
(5) Array () (array) definition
Array ([key =>]
Value
, ...
)
Key can be an integer or string
Value can be any value
For example:
[PHP] <?php $arr = Array ("foo" + "bar", +/-true); echo $arr ["foo"]; Bar Echo $arr [n]; 1 ?>
(6) Object (objects)
To initialize an object, use the new statement to instantiate the object into a variable.
Example:
[PHP] <?php //Create a class Foo classes foo { //Create a Do_foo method function Do_foo () { // Output Dong foo echo "Doing foo."; } } Create an instance of $bar $bar = new Foo; $bar instance calls the Do_foo method $bar->do_foo (); >
(7) resource (resources)
Waiting to be written ...
(8) Null
A special NULL value indicates that a variable has no value, not a variable that does not exist. The only possible value for a null type is NULL. ‘
A variable is considered NULL in the following cases:
is assigned a value of NULL.
has not been assigned a value.
Be unset ().
For example:
[PHP] <?php $var = NULL; ? >
Two related functions:
Is_null (): Determine if the variable is null
unset (): Delete variable declaration
The above is the PHP (c) php variable type content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!