PHP Data type conversions

Source: Internet
Author: User

PHP Data type conversion PHP does not require (or does not support) explicit type definitions in variable definitions; The variable type is determined by the context in which the variable is used. That is, if you assign a string value to the variable Var,var it becomes a string. If you assign an integer value to Var, it becomes an integer. An example of automatic type conversion for PHP is the plus sign "+". If any one operand is a floating-point number, all operands are treated as floating-point numbers, and the result is a floating-point number. Otherwise the operand is interpreted as an integer, and the result is an integer.  Note that this does not change the type of the operands themselves; it only changes how the operands are evaluated and the type of the expression itself. The casts allowed for type casts are: (int), (integer)-Converted to Integer (integer) (bool), (Boolean)-Converted to Boolean (Boolean) (float), (double), (real)-converted to floating-point type (f Loat) (String)-Convert to String (string)-Convert to binary string (string) (PHP 6) (array)-Convert to Array (object)-Convert to Object (object) (unset )-Convert to NULL (PHP 5) (binary) conversion will precede the result with the prefix ' B ', PHP 5.2.1 new. Note that spaces and tabs are allowed in parentheses to convert string literals and variables into binary strings (string): <?php$binary = (binary) $string; $binary = B "binary string";? > If you want to change the type of a variable, see Settype (); settype-sets the type of the variable bool Settype (mixed $var, string $type) sets the type of the variable var to type. The possible values for type are: "Boolean" (or "bool", starting with PHP 4.2.0) "integer" (or "int", from PHP 4.2.0) "Float" (only available after PHP 4.2.0, for use in older versions of "Doubl  E "now deactivated" string "" Array "" Object "" null "(from PHP 4.2.0) returns TRUE on success, or FALSE on failure. Intval (), Floatval (), STrval (), these three functions can also be converted 

  

PHP Data type conversions

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.