Simple analysis of PHP data type conversion

Source: Internet
Author: User

  This article mainly introduces the PHP data type conversion, the need for friends can refer to the

PHP does not need (or does not support) explicit type definitions in the variable definition, and the variable type is determined by the context in which the variable is used. In other words, if you assign a string value to a variable var,var, it becomes a string. If you assign an integer value to Var, it becomes an integer. An example of the automatic type conversion of   PHP is the plus sign "+". If any operand is a floating-point number, all operands are treated as floating-point numbers, and the result is floating-point numbers. Otherwise the operand is interpreted as an integer and the result is a whole number. Note that this does not change the type of the operands themselves; it only changes how the operands are evaluated and the type of expression itself.     Type casts allowed casts are:   (int), (integer)-Converted to integer (integer) • (bool), (Boolean)-to Boolean (Boolean) • (float), (double), (real)-Convert to float (float) • (string)-Convert to String (string) • (binary)-Convert to binary string (string) (PHP 6) • (array)-Convert to Array (arr AY) • (object)-Convert to Object (object) • (unset)-Conversion to NULL (PHP 5) (binary) conversion will precede the result with prefix ' B ', PHP 5.2.1 new.   Note allow spaces and tabs in parentheses   convert string literals and variables to binary strings (string):      code is as follows: <?php $binary = (binary) $ String $binary = B "binary string";?>     If you want to change the type of a variable, see Settype ();   settype-Set Variable type   BOOL Settype (mixed $var, string $type) sets the type of the variable var. The possible values for   type are:   "boolean" (or "bool", from PHP 4.2.0)   "integer" (or "int", from PHP 4.2.0)   "FLoat "(Available only after PHP 4.2.0," Double "used in older versions is now deactivated)  " string " " array " " Object " " null "(from PHP 4.2 .0) returns TRUE when it succeeds, or returns false.     intval (), Floatval (), Strval () when it fails, and the three functions can also be converted
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.