PHP data types
PHP 5 Data Type
##String (string), Integer (integer), Float (floating point), Boolean (Boolean), Array (array), Object (object), NULL (null value).PHP String (string)
A string is a sequence of characters, like "Hello world!". You can put any text in single and double quotes: Example<?php $x = "Hello world!"; echo $x; echo "<br>"; $x = 'Hello world!'; echo $x; ?>##PHP Integer(integer)
An integer is a number without decimals.
Integer rules:
· using ’ ’ s ’ s ’ s ’ s ‐ out to be digits (0-9)
The decimal point is
· The integer can be positive or negative
· The integer can be specified in three formats: decimal, hexadecimal (prefixed by 0x) or octal (prefixed by 0) ).
In the following examples we will test different numbers. The PHP var_dump() function returns the data type and value of the variable:
Example
<?php $x = 5985; var_dump($x); echo "<br>"; $x = -345; // 负数 var_dump($x); echo "<br>"; $x = 0x8C; // 十六进制数 var_dump($x); echo "<br>"; $x = 047; // 八进制数 var_dump($x); ?>
##PHP floating point type (float)
Floating point numbers are numbers with a decimal part, or in exponential form.In the following examples we will test different numbers. The PHP var_dump() function returns the data type and value of the variable:
Instance<?php $x = 10.365; var_dump($x); echo "<br>"; $x = 2.4e3; var_dump($x); echo "<br>"; $x = 8E-5; var_dump($x); ?>##PHP boolean
Boolean type can be TRUE or FALSE.
$x=true; $y=false;
Boolean type is usually used for conditional judgment. You will learn more about conditional control in the following chapters.
PHP array (array)
Arrays can store multiple values in one variable.
In the following example, an array is created, and then the PHP var_dump() function is used to return the data type and value of the array: Example
<?php $cars=array("Volvo","BMW","Toyota"); var_dump($cars); ?>
You will learn more about arrays in the following chapters.
The object data type can also be used to store data.
In PHP, objects must be declared. First, you must declare a class object using the class keyword. Classes are structures that can contain properties and methods.
Then we define the data type in the class, and then use the data type in the instantiated class:
Instance
<?php class Car { var $color; function Car($color="green") { $this->color = $color; } function what_color() { return $this->color; } } ?>Above The PHP keyword this in the instance is a pointer to the current object instance and does not point to any other object or class. You will learn more about objects in the following chapters.
PHP NULL value
NULL value means that the variable has no value. NULL is a value of data type NULL.
The NULL value indicates whether a variable has a null value. It can also be used to distinguish between data null values and NULL values. You can clear variable data by setting the variable value to NULL:
Example
<?php $x="Hello world!"; $x=null; var_dump($x); ?>
PHP resources (resource)
The resource type is introduced in PHP4.
When using resources, the system will automatically enable the garbage collection mechanism to release resources that are no longer used and avoid memory exhaustion. Therefore, resources rarely need to be released manually.
Name
## 2, Integer -2147483648 to +2147483647 (32 -bit)
3, floating -point type (Float or Double) 1.8E+308 (1.8 × 10308) 4. Boolean type (boolean) “True” or “False”. 5. Array . ) Collection of data and functions 7. Resource type (Resource) System data resources Pictures and other data resources