Learning notes for PHP data types

Source: Internet
Author: User
Tags numeric value type null

PHP Data type
PHP supports eight original types (type).

4 Kinds of scalar types:
String (String), Integer (integer), float (floating-point type, also double), Boolean (Boolean)
Two types of composite:
Array (array), Object (objects)
Two special types:
Resource (Resource), null (empty)

Boolean (Boolean)
Syntax: To specify a Boolean value, use the keyword TRUE or FALSE. All two are case insensitive.

When converted to Boolean, the following values are considered FALSE:
1> Boolean value FALSE
2> integer value 0 (0)
3> floating-point value 0.0 (0)
4> blank string and string "0″
5> an array with no member variables
6> Objects with no units
7> special type null (including variables not yet set)

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

Note: 1 and other non-0 values (whether positive or negative) are considered to be true!

=================================================================================
Shaping (integer)
Syntax: integer values can be specified in decimal, hexadecimal, or octal notation, preceded by an optional symbol (-or +).
If you use the octal symbol, you must add 0 (0) before the number, and 0x must precede the hexadecimal notation.

==================================================================================
Strings (String)

Three method definitions: single quotes, double quotes, delimiters.
String Conversions:
You can use the (string) tag or the Strval () function to convert a value to a string.
The Boolean value TRUE will be converted to the string "1″, and the value FALSE will be represented as" "(that is, an empty string).
Null is converted to an empty string.

string conversion to numeric value
When a string is evaluated as a number, the type and value of the result are determined according to the following rules.
If any of the characters ".", "E" or "E" are included, the string is evaluated as float. Otherwise it is treated as an integer. As shown in the following:

The code is as follows Copy Code
<?php
$foo = 1 + "10.5″;               //$foo is Float (11.5)
$foo = 1 + -1.3e3″;             / /$foo are float ( -1299)
$foo = 1 + "bob-1.3e3″;          //$foo is Integer (1)
$foo = 1 + "bob3″;                /$foo is integer (1)
$foo = 1 + ten Small Pigs ";      //$foo is integer (11)
$foo = 4 + "10.2 Little piggies";//$foo is float (14.2)
$foo = "10.0 Pigs" + 1;     & nbsp;   //$foo is float (one)
$foo = "10.0 Pigs" + 1.0;       // $foo is float

=====================================================================================
Arrays (Array)
The array in PHP is actually an ordered graph. A diagram is a type that maps values to the keys.

Utility functions:
The unset () function allows you to cancel the key name in an array. Be aware that the array will not rebuild the index.
===================================================================================
Null
A special NULL value indicates that a variable has no value. The only possible value for a null type is NULL.
Note: The NULL type is introduced in PHP 4.
A variable is considered NULL in the following cases:
is assigned null.
has not been assigned a value.
Be unset ().

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.