PHP 5Data Type
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:
<? $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:
<?PHP$x= 5985;Var_dump($x);Echo"<br>"; $x=-345;//Negative numberVar_dump($x);Echo"<br>"; $x= 0x8c;//Hexadecimal numberVar_dump($x);Echo"<br>";$x= 047;//octal numberVar_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
<? $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 judgment, more tutorials on conditional control.
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:
<? $cars=array("Volvo", "BMW", "Toyota"); Var_dump ($cars);? >
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:
<? PHP class car{ var$color; function Car ($color= "Green") { $this$color; } function What_color () { return$this,color; }}? >
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.
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:
<? PHP $x= "Hello world!" ; $x=null; Var_dump ($x);? >
PHP Quick Start Learning-4 (data type)