Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic types of variables in php

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what are the basic types of variables in php". In daily operation, I believe that many people have doubts about the basic types of variables in php. The editor consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "what are the basic types of variables in php?" Next, please follow the editor to study!

In php, there are four basic types of variables: 1, string (string) type, which is a continuous sequence of characters; 2, integer (integer) type; 3, float (floating point) type; 4, boolean (Boolean) type, only true and false two values.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In PHP, data types can be divided into three categories, namely scalar data types, compound data types and special data types.

Among them, the scalar data type is the most basic unit of the data structure, is the basic data type, and can only store one data. There are four types of scalar data in PHP, as shown in the following table:

Type function string (string) string is a continuous sequence of characters integer (integer) integer contains all integers, either positive or negative float (floating point) floating point type is also used to represent numbers, unlike integers, in addition to representing integers, it can also be used to represent decimal and exponential boolean (Boolean) the simplest data type, with only two values: true (true) / false (false)

String (string)

A string is a continuous sequence of characters. In other languages, characters and strings are two different data types, but in PHP, characters and strings are treated as string data types. In PHP, there are three ways to define a string, namely, single quotation mark mode, double quote mode, and Heredoc mode.

Integer (Integer)

In PHP, integer variables are called integer or int types and are used to represent an integer. The rules for integers are as follows:

The integer must have at least one number (0# 9)

Integers cannot contain commas or spaces

An integer cannot contain a decimal point

Integers can be positive or negative.

Integers must range from-2E31 to 2E31 and can be expressed in three formats, decimal, hexadecimal (prefixed with 0x), and octal (prefixed with 0).

Note that in the PHP7 version, strings containing hexadecimal characters are no longer treated as numbers, but as normal strings, such as:

Float (floating point)

Floating-point types, known as float types in PHP, also known as real numbers, can be used to store integers and decimals, and valid values range from 1.8E-308 to 1.8E+308. Floating-point numbers are more accurate than integer data types.

The sample code is as follows:

Boolean (Boolean)

Boolean has only two values, TRUE and FALSE (case-insensitive), meaning logical true and logical false. The sample code is as follows:

At this point, the study on "what are the basic types of variables in php" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report