Data types are the most basic knowledge points in PHP, and this article will learn more about data types.
String (String), Integer (integer), float (floating-point), Boolean (Boolean), Array (array), Object (objects), null (null value).
PHP string
A string is a sequence of characters, just like "Hello world!".
You can put any text in single and double quotation marks:
Instance
<?php $x = "Hello world!"; echo $x; echo "<br>"; $x = ' Hello world! '; echo $x;? >
PHP Integral type
An integer is a number that has no decimals.
Integer rule:
Integers must have at least one number (0-9)
Integers cannot contain commas or spaces
Integers are no decimal points.
Integers can be positive or negative
Integer types can be specified in three formats: decimal, hexadecimal (prefixed with 0x), or octal (prefixed with 0).
In the following example we will test for different numbers.
The PHP var_dump () function returns the data type and value of the variable:
Instance
<?php $x = 5985;var_dump ($x); echo "<br>"; $x =-345; Negative var_dump ($x); echo "<br>"; $x = 0x8c; Hexadecimal number var_dump ($x); echo "<br>"; $x = 047; Octal number Var_dump ($x);? >
PHP floating Point type
A float is a number with a decimal point, or an exponential form.
In the following example we will test for 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 type
The Boolean type can be TRUE or FALSE.
$x =true; $y =false;
Boolean is commonly used for conditional judgments. You'll learn more about conditional control in the next sections.
PHP arrays
An array can store multiple values in a variable.
An array is created in the following instance, and then the data type and value of the array are returned using the PHP Var_dump () function:
Instance
<?php $cars =array ("Volvo", "BMW", "Toyota"); Var_dump ($cars);? >
You'll learn more about arrays in the next sections.
PHP Object
Object data types can also be used to store data.
In PHP, the object must be declared.
First, you must declare the class object using the Class keyword. A class is a structure 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
The PHP keyword in the above example 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 next chapters.
PHP NULL Value
A NULL value indicates that the variable has no value. Null is a value with a data type of NULL.
A null value indicates whether a variable is a null value. It can also be used to distinguish between null values and data nulls.
Variable data can be emptied by setting the value of the variable to NULL:
Instance
<?php$x= "Hello world!"; $x =null;var_dump ($x);? >
This article introduces in detail the data type, the more study material clear concerns the PHP Chinese network to be able to watch.