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 data types of PHP

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

Share

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

This article mainly introduces what data types PHP has, which can be used for reference by interested friends. I hope you can learn a lot after reading this article. Let's take a look at it.

There are 8 data types in PHP:

Type name Type representation value bool Boolean true,falseinteger Integer-2147483647-2147483648string string length depends on the machine memory float floating point maximum 1.8e308object object instantiation $obj=new person () through new; array array type $arr=array; / / one-dimensional array resourse

Null Null value null

Boolean bool:

For other types, we can use (bool) or (boolean) to cast eg: (bool) 1=true

The following situations default to false when forced conversion:

Conversion result Boolean false var_dump ((bool) false) bool (false) integer 0 var_dump ((bool) 0); bool (false) floating point 0.0 var_dump ((bool) 0.0); bool (false) string'0' var_dump ((bool)'0'); bool (false) empty array $arr=array () Var_dump ((bool) $arr) bool (false) empty objects that do not contain any member variables are only used in PHP4, PHP5 for truebool (false) NULL or unassigned variables var_dump ((bool) NULL) bool (false) SimpleXML objects bool (false) generated from XML documents without any tags (false)

The string '0.0' is converted to bool (true)

Note:-1 and other non-zero values (positive or negative) are true

Integer integer:

The range of integers-2147483647 Murray 2147483647. If this value is exceeded, it will be automatically converted to float.

We can use echo PHP_INT_SZIE to output the word length of integer, which is machine-related. The maximum value of echo PHP_INT_MAX output integer

There is no divisible operation in PHP. If performing 1ap2 results in 0.5 of float, if you want to achieve the effect of divisible, you can use (int) (1gamma 2) = 0 or use round (25ip 7) = 4.

Force conversion to integer (int) or (integer) Bool ture to 1, false to 0

Floating point float:

Maximum value range: 1.8e308 does not know what the minimum value is? Ask the master to let me know

The word length of floating-point numbers is also related to machines. There seems to be no PHP_FLOAT_SIZE. Ask the master to tell you how to reach floating-point number length.

String type string:

Four ways to define a string:

1. Single quotation mark

two。 Double quotation marks

3.heredoc grammatical structure

4.nowdoc syntax structure (after PHP5.3.0)

Single quotation mark

Single quotation marks define the most original string, in which everything is treated as a string. If the string contains single quotation marks, it can be escaped with\.

Double quotation marks

Strings defined in double quotes parse some special characters (\ n,\ b) and variables

Instead of converting the variable to a string (string), you can place the variable in double quotes:

$num=10

$str = "$num"; / / $str is 10 of string type

Heredoc grammatical structure

'All these days are twofold = >'b')

$obj= (object) $arr

Echo $obj- > one / / output result is a

Note: this is by key array if there is no character key array, I do not know how to access, who knows want to tell the younger brother, thank you.

For other values

The copy code is as follows:

[php]

$obj1= (object) 'jiang'

Echo $obj1- > scalar;// output result jiang

NULL null type

Null is case-insensitive. There is only one value for the NULL type, indicating that a variable has no value. The following three cases are considered to be NULL.

1. Assigned to NULL

two。 Has not been assigned yet

3. By unset ()

PHP type comparison tables

Comparisons of $x with PHP functionsExpressiongettype () empty () is_null () isset () boolean: if ($x) $x = "; stringTRUEFALSETRUEFALSE$x = nullNULLTRUETRUEFALSEFALSEvar $x null _ TRUETRUEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSETRUETRUESESESEUETRUESESETUETRUESETUETRUESETERUETRUESETRUETRUESETERUETRUESETRUETRUESETUETRUESETRUETRUESETRESETRUESETRUESESETRUESETRUESESETRUESESETRUESETRESETRUESETRUESESETRUESESETRUESETRESEUESETRESEUESETUESETUESETRUESETUESETRESEUESETRESEUESEUEFALSETRUESESETRUESETRUESESETRUESETRUEFALSETRUETRUESETRUESETRESEUESEUESETUESESETRUESETRUESETRESEUESETUESERESEUESETUESESETRUESETRUESETRUESETRUESEUSEUESETRUESETRUESETRUE

TRUEFALSE10-1 "1"0"- 1" NULLarray () "php" TRUETRUEFALSETRUEFALSETRUETRUEFALSETRUEFALSEFALSETRUEFALSEFALSEFALSETRUEFALSETRUEFALSEFALSETRUEFALSETRUETRUEFALSETRUE1TRUEFALSETRUEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSE0FALSETRUEFALSETRUEFALSEFALSETRUEFALSETRUEFALSETRUETRUE-1TRUEFALSEFALSEFALSETRUEFALSEFALSETRUEFALSEFALSEFALSEFALSE "1" TRUEFALSETRUEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSE "0" FALSETRUEFALSETRUEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSE "- 1" TRUEFALSEFALSEFALSETRUEFALSEFALSETRUEFALSEFALSEFALSEFALSENULLFALSETRUEFALSETRUEFALSEFALSEFALSEFALSETRUETRUEFALSETRUEarray () FALSETRUEFALSEFALSEFALSEFALSEFALSEFALSETRUETRUEFALSEFALSE "php" TRUEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSETRUEFALSE "" FALSETRUEFALSETRUEFALSEFALSEFALSEFALSETRUEFALSEFALSETRUEStrict comparisons with = =

TRUEFALSE10-1 "1"0"1" NULLarray () "php"TRUETRUEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSE1FALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSE0FALSEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSE-1FALSEFALSEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSEFALSE" 1 "FALSEFALSEFALSEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSE" 0 "FALSEFALSEFALSEFALSEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSE"-1 "FALSEFALSEFALSEFALSEFALSEFALSEFALSETRUEFALSEFALSEFALSEFALSENULLFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSETRUEFALSEFALSEFALSEarray () FALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSETRUEFALSEFALSE" php "FALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSETRUEFALSE"FALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSETRUE" thank you for reading this article carefully. I hope the article "what are the data types of PHP" shared by the editor will be helpful to you. At the same time, I also hope you can support us, pay attention to the industry information channel, and more related knowledge is waiting for you to learn!

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