Data Types in PHP (1) _php tutorial

Source: Internet
Author: User
PHP supports eight primitive types.

four types of scalar:

Boolean Type (Boolean)

Integral type (integer)

Float (float) (floating-point number, also "double")

Strings (String)

Two types of composite:

Arrays (Array)

Objects (object)

Finally, there are two special types:

Resources (Resource)

Null

To ensure the readability of the Code, this manual also describes some pseudo-types:

Mixed (mixed)

Numbers (number)

Feedback (callback)

You might also read some references to the double-precision type. In fact double and float are the same, because of some historical reasons, both names exist at the same time.

The type of the variable is usually not set by the programmer, but rather is determined by the context in which PHP is used according to the variable.

Note: If you want to see the value and type of an expression, use Var_dump ().

Note: If you just want an easy-to-read type of expression for debugging, use GetType (). To view a type, do not use GetType () and use the Is_type function. Here are some examples:

       

If you want to cast a variable to a type, you can use a cast or settype () function on it.

Note that the variable will behave differently depending on its current type. See type tricks for more information. In addition, you can refer to the PHP type comparison table to see different types of comparisons between the examples.

Boolean type

This is the simplest type. Boolean expresses the truth value, which can be TRUE or FALSE.

Note: The Boolean type is introduced in PHP 4.

Grammar

To specify a Boolean value, use the keyword TRUE or FALSE. Two are case insensitive.

     

Typically you return a Boolean value with some operators and pass it to the process control.

= = is an operator which test//equality and returns a booleanif ($action = = "Show_version") {   echo "the version is 1.23 ";} This is not necessary...if ($show _separators = = TRUE) {   echo "n";} Because you can simply Typeif ($show _separators) {   

Convert to a Boolean value

To explicitly convert a value to a Boolean, use either (BOOL) or (Boolean) to cast. However, in many cases it is not necessary to cast, because when an operator, function, or process control requires a Boolean parameter, the value is automatically converted.

See also type-trick.

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

Boolean value FALSE

Integer value 0 (0)

Floating-point value 0.0 (0)

Blank string and string "0"

An array with no member variables

An object without a cell

Special type null (including variables that have not been set)

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

     

1

http://www.bkjia.com/PHPjc/446741.html www.bkjia.com true http://www.bkjia.com/PHPjc/446741.html techarticle PHP supports eight primitive types. Four scalar types: Boolean (Boolean) integer (integer) floating-point (float) (floating-point, also as Double) string (string) two ...

  • 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.