Learning notes for php Data types

Source: Internet
Author: User
Tags type null
There are eight scalar types in php, including string, integer, float, and boolean) and composite type and resource (resource), NUL... there are eight scalar types in php, including string, integer, float, and boolean) and the composite type and resource (resource), NULL (NULL). let's take a look.

Php data type

Php supports eight primitive types ).

Four scalar types:String (string), integer (integer), float (float type, also double), boolean (boolean type)

Two composite types:Array (array), object (object)

Two special types:Resource, NULL)

Boolean)

Syntax:To specify a Boolean value, use the TRUE or FALSE keywords. Both values are case insensitive.

When converted to boolean, the following values are considered FALSE:

1> boolean value FALSE

2> integer value 0 (0)

3> float value: 0.0 (0)

4> blank string and string "0"

5> arrays without member variables

6> objects without cells

7> Special type NULL (including unset variables)

All other values are considered to be TRUE (including any resources ).

Note:-1 is considered TRUE like other non-zero values (both positive and negative values!

Integer)

Syntax:The integer value can be specified in decimal, hexadecimal, or octal notation. an optional symbol (-or +) can be added before ).

If the octal symbol is used, 0 (zero) must be added before the number, and 0x must be added before the hexadecimal symbol.

String)

Three methods are defined: single quotation marks, double quotation marks, and delimiters.

String conversion:

You can use the (string) flag or the strval () function to convert a value to a string.

The Boolean value TRUE is converted to the string "1", and the value "FALSE" is expressed as "" (an empty string ).

NULL is converted to a NULL string.

Convert string to numeric value

When a string is evaluated as a number, the result type and value are determined according to the following rules.

If the string contains any of the characters ".", "e", or "E", it is evaluated as a float. Otherwise, it is treated as an integer, as shown below:

 

Array)

Arrays in PHP are actually an ordered graph. A graph is a type that maps values to keys.

Practical functions:

The unset () function allows you to cancel the key name in an array. Note that the array will not be re-indexed.

NULL

A special NULL value indicates that a variable has no value. The only possible value of the NULL type is NULL.

Note: The NULL type is introduced in PHP 4.

The variable is considered NULL in the following cases:

The value is NULL.

Not assigned.

Unset ().

Article address:

Reprint at will ^ please include the address of this 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.