PHP 5 data types
PHP’s data types include the following,
Integer(integer type)
String(String)
Float(Float type),
Boolean(Boolean type)
Array(array)
Object(object)
NULL(null value)
View data type
1. gettype (pass in a variable) can get the type of the variable
2. var_dump (pass in a variable) output variable type and value (most commonly used)
var_dump() is a function. Insert variables between brackets (). This function will print out the data type and also display the length and value of the variable accordingly.
##Integer type (int)
The integer type is divided into:
1. 10-base system 2.8-base system( Understand, basically don’t use it)
3.16 base(Understand, basically don’t use it)
Octal system declaration: starts with 0, followed by an integer from 0 to 7 (Understand knowledge points) Hexadecimal declaration: Starting with 0x, followed by 0-f, the abcdef of 0x is not case-sensitive. (Understand knowledge points)Integer rules:
· An integer must have at least one digit (0-9) · The integer cannot contain commas or spaces · The integer cannot have a decimal point · The integer can be positive or negative · The integer can be specified in three formats: decimal, hexadecimal System (prefix is 0x) or octal (prefix is 0)
#Example
In the following example we will test different numbers.
"; $x = -345; // 负数 var_dump($x); echo "
"; $x = 0x8C; // 十六进制数 var_dump($x); echo "
"; $x = 047; // 八进制数 var_dump($x); ?>
##String
Strings are all our visible and invisible characters. They are what we say in daily life. What I want to say is: "Li Wenkai is so handsome." ” or “Sister Feng, I love you!” Strings are all the characters that people can see that I want to express.
For example, you can see the characters: I would like to become you, the prince you love, a house, a car and money, in a fairy tale.There are three ways to declare a string in PHP language:
1. Use single quotes to declare
2. Use double quotes to declare
3. Use character delimiters Statement (used when a very large string needs to be entered)
1.Single quote statementUse English half-foot single quotes to wrap the string, as follows:
$zifuchuan='I am a single quote';
1.Double quote statementAdd double quotes on both sides of the string, as follows:
$zifuchuan="I am double quotes";
3. Character declaration
1). Write three less than signs (<<<) after the equal sign after the variable.
2). Then write characters after <<< (English uppercase characters are recommended). As in the following example: ABC
3). Then change the line and write any characters you want
4). After writing, go to the top line. At the beginning of the line, write the characters following <<< and a semicolon. As in the following example: ABC;
$dingjie = <<If
It must be here Roll the calf
Far, get as far away from me
ABC;
?>
##Example
In the following example, we will output a string.
"; $x = 'Hello world!'; var_dump($x) ; ?>
##Float
The so-called floating point type can be understood as: the decimal in our mathematics.
Example
We use echo and Print to output floating point types respectively
"; //声明变量$fl 的值为0.8873 $fl = 0.8873; var_dump($fl); ?>echo directly outputs 12121.3132, and var_dump The output is 0.8873, and it also shows that the type of variable $fl is float.
##Boolean type(bool)
The Boolean type is: true and false.The translation of true and false in English is:· true (true)
· false (false)
Therefore, we can do this in the PHP code statement.
//Declare a variable (Pinyin) as Boolean
$buer = true;
//State a variable (English)
$bool = false;
?>
Note: Do not add quotation marks aroundfor true and false.
#Array
Object (Object)
#NULL (null value)class Car
{
var $color;
function Car($color="green") {
$this->color = $color;
}
function what_color() {
return $this->color;
Knowledge about objects, just know it now
Empty means null in English, which means nothing. Null is not false, not 0, and not a space.
There are three main situations that will produce a null type:1. The value of a variable explicitly specified as NULL through variable assignment
2. A variable has no Give any value
3. Use the function unset() to destroy the variable
Let’s demonstrate it with code
Next we will explain two things related to null Functions, these two functions are very commonly used.
empty()
You can pass a variable into the middle of the brackets. If the value of this variable is false or null, it returns true.
Example
##The above experiment proves that $apple is null. Place the apple in the middle of empty. The result is a true interval.
isset()You can pass one or more variables into the middle of the brackets, and separate variables with commas. As long as there is a variable that is null, it returns false. Otherwise, returns true.
Example
##unset()The function of this function is to destroy variables. Insert the variable name you want to destroy between the unset (variable) brackets, and the variable will be destroyed.