Home > Backend Development > PHP Tutorial > PHP data data types_PHP tutorial

PHP data data types_PHP tutorial

WBOY
Release: 2016-07-13 10:15:57
Original
811 people have browsed it

php data data type

I have been learning PHP for a long time, but I have never understood the resource conversion in PHP. I saw it is similar to Java, but after a closer look, I found that there are still many differences, so I will talk about my own learning in PHP. Thoughts:

First of all, we all know that php is a weakly typed language? (Because any variable can be saved to a variable starting with $, so PHP is a weakly typed language, but it does not mean that it cannot specify the data type, it is just that the saving method is special), data type?

What data type: refers to a certain data type composed of a certain data structure and special operations defined on the data structure.

Then you know that there are various data types in php, integer, integer, floating point, string, Boolean, array, object, resource, NULL, etc., simple types ( Scalar data type), each data stores a value; but sometimes we may not understand each of these places. In order to deepen my understanding, let me summarize:

1 Because the maximum storage space that can be used by integers is limited.

An integer occupies 4 bytes

One byte = 8 bits

You need to use one bit to represent the sign, the highest bit (31), 0 is positive, 1 is negative

This number can be represented by PHP's predefined constant PHP_INT_MAX. If the number continues to increase, it will become a floating point number,

2 If you observe carefully, you will find that the absolute value of the minimum value is one greater than the absolute value of the maximum number (determined by the complement computer, and will be considered during bit operations)

3.

When defining integer data, PHP supports three base representations (representing a number, which can have three forms----decimal, octal , hexadecimal

Octal: starts with 0.

Hexadecimal: starting with 0x.

Decimal: Regular!

Emphasize that 0 or 0x is not part of the number, it is just a syntax used by PHP to distinguish different bases!

4. Manual base conversion

Rule: Decimal number, divided by the target base. You will get the remainder and quotient. If the quotient is not zero, continue to divide the quotient by the target base to obtain the remainder and quotient. Until the quotient reaches zero, just connect all the remainders from bottom to top:

Functions commonly used in programs

Dec,10

Bin,2

Oct,8

Hex,16

Decbin();10to2

Dechex();10 to 16

Octdec();8 to 10

5 floating point number

PHP’s floating point numbers do not distinguish between single precision and double precision. PHP only implements double precision. Floating point numbers in Php are double precision.

1) Floating point numbers support scientific notation

2) The number of significant digits that Php can represent14 digitsSignificant digits

3) Floating point numbers cannot be compared using floating point numbers

For example:

if(1-0.2==0.8){//Output true

}

if(1-0.8==0.2){//output false

}


Cause of this problem:

When the decimal is saved, it needs to be converted into binary. Very few numbers can be expressed completely.

How to convert decimal to binary:

Multiply by 2 and take the integer part of the product:

All floating point numbers store approximate values, not precise values.

6 Boolean

Represents the truth or falsehood of a logical relationship

7. Composite data type, one data saves multiple values

Array, object

8 special types

NULL type





www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/900031.htmlTechArticlePHP data data types I have studied PHP for a long time, but I have never understood the resource conversion of PHP. See the following Java is almost the same, but after taking a closer look, I found that there are still many differences...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template