PHP variable type forced conversion _ PHP Tutorial

Source: Internet
Author: User
PHP variable type forced conversion. That is to say, if a string value is assigned to the variable var, var becomes a string. If another integer value is assigned to var, it becomes an integer. The type in PHP is mandatory. if a string value is assigned to the variable var, var becomes a string. If another integer value is assigned to var, it becomes an integer.
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.

The code is as follows:


$ Foo = 10;
Echo "before conversion: \ $ foo =". $ foo; // output an integer
Echo"
"// Output: $ foo = 10
Echo"
";
$ Foo = (boolean) $ foo; // force convert to boolean
Echo "converted: \ $ foo =". $ foo; // output: $ foo = 1
?>


The following mandatory conversions are allowed:
(Int), (integer)-convert to integer
(Bool), (boolean)-convert to boolean
(Float), (double), (real)-convert to floating point type
(String)-convert to string
(Array)-convert to an array
(Object)-convert to object

Callback var and var are a string. If another integer value is assigned to var, it becomes an integer. Forced type in PHP...

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.