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)

So-called integer type , which is the integer that everyone learns in mathematics.

Integer type——Integer, also known as integer in English. English abbreviation: 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.

<?php
 $x = 5985;     //十进制
 var_dump($x);
 echo "<br>";
 $x = -345; // 负数
 var_dump($x);
 echo "<br>";
 $x = 0x8C; // 十六进制数
 var_dump($x);
 echo "<br>";
 $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. <html><title></title></html> ^@@@#@ my name is xiaoshenyang

and above text, HTML tags, special characters and English, etc., we all Think it is a string

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 statement Use English half-foot single quotes to wrap the string, as follows:

$zifuchuan= 'I am a single quote';

1. Double quote statement Add 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;

<?php

$dingjie = <<<ABC
If
It must be here Roll the calf
                                                                                                                                                                                                                                                                     Far, get as far away from me</h1>
ABC;
?>




##Example


In the following example, we will output a string.

<?php
 $x = "Hello world!";
 echo $x;
 echo "<br>";
 $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

<?php
 //声明变量fudian的值为12121.3132
 $fudian = 12121.3132;
 echo $fudian;
 echo "<br>";
 //声明变量$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.

<?php
//Declare a variable (Pinyin) as Boolean
$buer = true;
//State a variable (English)
$bool = false;
?>
Note: Do not add quotation marks around for true and false.


#Array

An array stores multiple values ​​in a variable. Think like this:

<?php
 $cars=array("Volvo","BMW","SAAB");
 var_dump($cars);
 ?>

You will learn more about arrays later in this tutorial.


Object (Object)

The object is to store data data type and information about how to process the data.

In PHP, objects must be declared explicitly.

First we must declare the class of the object. For this we use the class keyword. A class is a structure containing properties and methods.

Then we define the data type in the object class and then use this data type in instances of that class:

<?php class Car
{
var $color;
function Car($color="green") {
$this->color = $color;
}
function what_color() {
            return $this->color;
                                                                                                                                                                              Knowledge about objects, just know it now


#NULL (null value)


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

<?php
 //声明变量为null
 $n = null;
 var_dump($n);
 
 //var_dump显示输出变量$meiyou,看看结果是什么?
 var_dump($meiyou);
 
 //声明一个变量$iphone的值为字符串的手机
 $iphone = '手机';
 //unset销毁掉一个变量
 unset($iphone);
 var_dump($iphone);
 ?>

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

<?php
 header("Content-type:text/html;charset=utf-8"); //设置utf-8编码
 $apple = null;
 if(empty($apple)){
     echo '执行了真区间';
 }else{
     echo '行了假区间';
 }
 ?>

##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

<?php
 $one = 10;
 $two = false;
 $three = 0;
 $four = null;
 $result = isset($one , $two , $three , $four);
 //执行看看结果,是不是
 var_dump($result);
 ?>


##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.


Continuing Learning
||
<?php $x = 5985; //十进制 var_dump($x); echo "<br>"; $x = -345; // 负数 var_dump($x); echo "<br>"; $x = 0x8C; // 十六进制数 var_dump($x); echo "<br>"; $x = 047; // 八进制数 var_dump($x); ?>
submitReset Code