PHP section 2 data type conversion _ PHP Tutorial

Source: Internet
Author: User
Data type conversion in section 2 of PHP. In the following cases, the variable is considered NULL: The value is NULL. Not assigned. Unset (). The NULL type has only one value, that is, the case-insensitive keyword NULL (

In the following cases, the variable is considered to beNULL:

  • AssignedNULL.

  • Not assigned.

  • QuiltUnset ().

NULLThe type has only one value, which is a case-insensitive keyword.NULL(You can write NULL or null ).

Convert a variableNullType will delete the variable and unset its value.

Type conversion

PHP does not need (or does not support) explicit type definitions in variable definitions. variable types are determined by the context in which the variable is used. That is to say, if a string value is assigned to the variablevar,varIt becomes a string. If another integer value is assignedvarThen it becomes an integer.

An example of PHP's automatic type conversion is the plus sign "+ ". If any operand is a floating-point number, all the operands are treated as floating-point numbers, and the result is also a floating-point number. Otherwise, the operand is interpreted as an integer and the result is also an integer. Note that this does not change the type of these operands. it only changes how these operands are evaluated and the type of the expressions.

The forced type conversion in PHP is very similar to that in C: add the target type enclosed in parentheses before the variable to be converted.

  • (Int), (integer)-to convertInteger)
  • (Bool), (boolean)-convertBoolean)
  • (Float), (double), (real)-convertFloat)
  • (String)-convertString)
  • (Binary)-convert to binaryString)(PHP 6)
  • (Array)-convertArray)
  • (Object)-convertObject)
  • (Unset)-convertNULL(PHP 5)

(Binary) the prefix 'B' is added before the result, and PHP 5.2.1 is added.

Required NULL: The value is NULL. Not assigned. Unset (). The NULL type has only one value, that is, the case-insensitive keyword NULL (...

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.