PHP Data type conversion and variable

Source: Internet
Author: User
In PHP, you can use type conversion to convert a variable or value to another type. This type of conversion is the same as that in C language. You only need to insert the temporary data type to be converted in parentheses before the variable to be converted.

1. type conversion
In PHP, you can use type conversion to convert a variable or value to another type. This type of conversion is the same as that in C language. You only need to insert the temporary data type to be converted in parentheses before the variable to be converted.

For example, we can declare two variables in the previous article using type conversion.
$ Totalqty = 0;
$ Totalamount = (float) $ totalqty;

The 2nd line of code refers to "retrieving the value of the variable saved in $ totalqty, interpreting it as a floating point type, and saving it in $ totalamount. The $ totalamount variable changes to the floating point type. The converted variable does not change its type, so $ totalqty is still an integer.

Implicit or explicit type conversion may occur.

2. variable
PHP provides a variable of another type-variable. Variable variables allow us to dynamically change the name of a variable. We can see that PHP has a great degree of freedom in this regard-all languages allow changing the value of a variable, but not many languages allow changing the type of a variable, as for languages that support variable name change, there will be fewer languages. This feature uses the value of one variable as the name of another variable. For example, we can set:
$ Username = 'feng ';
Therefore, we can replace $ feng with $ username. For example, we can set the value of $ feng:
$ Username = 100;
This is equivalent:
$ Feng = 100;
This code does not seem easy to understand. I will introduce it in detail in later articles.

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.