search
HomeBackend DevelopmentPHP TutorialPHP data data types_PHP tutorial

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...
Statement
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool