Brief introduction
PHP supports 8 basic data types
Four types of scalar:
Boolen
Integer
Float (double)
String
Two kinds of composite types:
Array
Object (Objects)
Finally, there are two special types:
Resource (resources)
Null (NULL)
There are other pseudo-types:
Mixed
Number
Callback
and the pseudo-variable $ ...
Note: If you want to see the value and type of an expression, use Var_dump ().
If you just want an easy-to-read type of expression for debugging, use GetType (). To determine a type, do not use GetType () and use the Is_type function.
<?php
$a _bool =true;//bool
$a _str1= "foo";//string
$a _str2= "foo";//string
$a _int=12;//integer
Echo GetType ($a _bool)//prints out:boolean//Be careful not to write A_bool, before adding $
echo GetType ($a _int);//prints out : integer//note Do not write A_bool, the front to add $
/*
If This is a integer,increment it by four
*/
if (is_int ($a _int))
& nbsp; {
$a _int+=4;
echo $a _int;
}
//if $a _bool is a string,print it out
if (is_string ($a _bool))
{
echo "String: $a _bool";
}
?
If you want to cast a variable to a type, you can use a cast or settype () function on it.
Data Types for PHP