PHP Data type
String (String), Integer (int), float (float), Boolean (Boolean), array (arrays), object,
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:
1 <? PHP 2 $x = "Hello world!" ; 3 Echo $x ; 4 $x = ' Hello world! ' ; 5 Echo $x ; 6 ?>
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 include commas or spaces
- Integers are no decimal points.
- 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:
1<?PHP2 $x= 5985;//integer3 Var_dump($x);4 Echo"<br>";5 6 $x=-345;//Negative number7 Var_dump($x);8 Echo"<br>";9 Ten $x= 0x8c;//Hexadecimal number One Var_dump($x); A Echo"<br>"; - - $x= 047;//octal number the Var_dump($x); -?>
PHP floating Point type
A floating-point type is a number with a decimal part, 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:
1<?PHP2 $x= 10.365;3 Var_dump($x);4 Echo"<br>";5 6 $x= 2.4e3;7 Var_dump($x);8 Echo"<br>";9 Ten $x= 8E-5; One Var_dump($x); A?>
PHP Boolean type
The Boolean type can be True or false.
1 $x true ; 2 $y false ;
Boolean is commonly used for conditional judgment. 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 the data type and value of the array are returned using the PHP Var_dump () function:
1 <? PHP 2 $cars Array ("Volvo", "BMW", "Toyota"); 3 Var_dump ($cars); 4 ?>
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 by 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:
1<?PHP2 classCar3 {4 var $color;5 functionCar ($color= "Green")6 {7 $this->color =$color;8 }9 Ten functionWhat_color () One { A return $this-color; - } - } the?>
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'll 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 null data type.
A null value indicates whether a variable is a null value. The same can be used for data null and null values.
Variable data can be emptied by setting the variable to null:
<? PHP $x = "Hello world!" ; $x NULL ; Var_dump ($x);? >
6. PHP Tutorial _php data types