What are the PHP data types? Summary of PHP data types

Source: Internet
Author: User
Tags null null scalar
What does this article bring to you about PHP data types? PHP Data Type Summary, there is a certain reference value, the need for friends can refer to, I hope to help you.

First, data type introduction

1, PHP is a weak type check language, the data type is determined by the context of the program, that is, the specific type is determined by the stored data
2. Three kinds of data types: scalar data types, composite data types, and special data types
3. Scalar data type

    • Boolean Boolean type

    • Integer integer type

    • Float/double floating Point type

    • String strings

4. Composite data type

    • Array arrays

    • Object objects

5. Special data types

    • Resource Resources

    • NULL NULL

Second, scalar data types

Boolean Type (Boolean)
1, save a logical true, or false

2, the following conditions may also be regarded as false:
A Boolean value of False, an integer value of 0, a float value of 0.0, an empty string, and a string of "0".
An array with no member variables, an object with no cells, NULL

<?php//Boolean data $ A = true; $b = False;//var_dump () function can return the type and value of an expression var_dump ($a);      The result is  bool (true) echo "<br>"; Var_dump ($b);      The result is  bool (false)?>

integral Type (integer)
1, can only contain integers, you may use the symbol to represent positive negative numbers

2. Unsigned integers are not supported in PHP

Integer-Data $ A = +3; $b = -5;var_dump ($a);      The result is an  int (3) echo "<br>"; Var_dump ($b);      The result is an  int ( -5) echo "<br>"; echo $a + $b;        The result is  -2echo "<br>";

Floating-point type (float/double)

1. Float type is used to store numbers that include decimals, which is an approximate value

2, Scientific counting method: 10.1e10

Floating-point data $ A = 1.56; $b = 1.5e3;var_dump ($a);      The result is a  float (1.56) echo "<br>"; Var_dump ($b);      The result is  float (1500)

String Type (strings)
1. Single quotation mark
The variables that appear in single quotes are output as-is, and the PHP engine does not parse it, so single quotes define the most efficient strings

2. Double quotation marks
The variables contained in the double quotes are automatically replaced with the variable values

3. Delimiter <<<
The delimiter is followed by an identifier indicating the beginning, and finally the same identifier ending the string
The end identifier must start at the first column of the row, except that the semicolon cannot contain any other characters

String Type $STR = ' string '; Echo ' str is $str <br> ';//The result is that STR is $str     single quote variable remains as-is output echo "str is $str <br>";  The result is that STR is a string-type  double quotation mark that resolves the variable $str2 = <<<STR2 which is the literal in the delimiter Str2;echo $str 2;            The result  is that this is the text in the delimiter

Three, composite data types

Arrays (Array)
1, the array is a series of related data collection, in a certain way to arrange, to form a whole
2, can be the same data type, can also be different data types
3. The index of an array in PHP can be a number, or it can be a string

The same type of element $array1 = array (1,3,5,7,9);//different type element                    $array 2 = array (1, ' Hello ', true,3.14);//index is number             $array 3 = Array (1= > ' A ',2=> ' B ',3=> ' C ');//index is a string                $array 4 = Array (' A ' = ' apple ', ' B ' + = ' banana ', ' c ' = ' orange ');

IV. Special Data types

Resources (Resource)
1, the resource is a special type of variable, it holds a reference to the external data source, such as file, database connection, etc., until the end of the communication
2, Database persistent connection is a kind of special resources, it will not be released by the garbage collection system, need to manually release

Null (NULL)

1, is assigned a value of NULL
2. The variable is not assigned a value
3. After assigning variables, use the unset () function to clear

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.