Php Data type conversion, php Data Type _ PHP Tutorial

Source: Internet
Author: User
Php Data type conversion, php data type. Php Data Type Conversion. php Data types PHP does not need (or do not support) explicit type definitions in variable definitions. variable types are determined by the context in which the variable is used. That is, php Data type conversion, and php Data 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.

Type forced conversion

The following mandatory conversions are allowed:

  • (Int), (integer)-convert to integer (integer)
  • (Bool), (boolean)-convert to boolean (boolean)
  • (Float), (double), (real)-convert to float)
  • (String)-convert to string (string)
  • (Binary)-convert to a binary string (string) (PHP 6)
  • (Array)-convert to an array (array)
  • (Object)-convert to object)
  • (Unset)-convert to NULL (PHP 5)

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

Note that empty spaces and tabs are allowed in parentheses.

Convert string text and variables to a binary string ):

 

To change the type of a variable, see settype ();

Settype-set the variable type

Bool Settype(Mixed $ Var, String $ Type)

Change the variableVarToType.

TypeThe possible values are:

  • "Boolean" (or "bool", starting from PHP 4.2.0)
  • "Integer" (or "int", starting from PHP 4.2.0)
  • "Float" (only available after PHP 4.2.0, and "double" used in earlier versions is disabled now)
  • "String"
  • "Array"
  • "Object"
  • "Null" (from PHP 4.2.0)

Return if successfulTRUE, Or return when the failure occurs.FALSE.

Intval (), floatval (), strval (), these three functions can also be converted

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

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