Home  >  Article  >  Backend Development  >  PHP kernel exploration: variable type conversion

PHP kernel exploration: variable type conversion

WBOY
WBOYOriginal
2016-07-30 13:29:321014browse

PHP is a weakly typed dynamic language. We already know that PHP variables are stored in a container called ZVAL. ZVAL contains the type of the variable and the values ​​of various types of variables. Variables in PHP do not require explicit data type definitions, and any type of data can be assigned to variables. There are two types of data type conversion between PHP variables: implicit and explicit conversion.
Implicit type conversion
Implicit type conversion, also known as automatic type conversion, refers to type conversion that is automatically completed by the programming language without the need for programmers to write code. In PHP, the implicit conversions we often encounter are:

1. Direct variable assignment operation
In PHP, direct assignment to variables is the simplest way of implicit type conversion, and it is also the most common way for us. Perhaps we are so accustomed to it that we do not feel the changes in variables. In a direct assignment operation, the data type of the variable is determined by the assigned value, that is, the data type of the lvalue is determined by the data type of the rvalue. For example, when assigning a string type data to a variable, no matter what type of variable the variable was before, the variable is now a string type variable. Look at a piece of code:

<code><span>$string</span> = <span>"To love someone sincerely means to love all the people,  to love the world and life,  too."</span><span>$integer</span> = <span>10</span>;
<span>$string</span> = <span>$integer</span>;</code>

The above code, when the third line of code is executed, strin g Change amount of category typejust is onepiecewhole shaped .passVLD ExpandExpand can to check toth ThreetimesFuValue fuckmake of between generationcode andfuckmakecount of category type, again to Endowment worth of the mostafterrealnow forzen dassig nt ovariab leLetter Count. This in front of Noodles smallfestivalmediumalready Details FineIntroductionShao passed .Iwethis eachcase isveryJian Single of kindEndowment Value, In Sourcecode is straight pick up will

The above has introduced PHP kernel exploration: variable type conversion, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn