Home > Backend Development > PHP Tutorial > Data Types PHP Section 2 Data Type Conversion

Data Types PHP Section 2 Data Type Conversion

WBOY
Release: 2016-07-29 08:48:32
Original
824 people have browsed it

A variable is considered NULL if:

  • is assigned a value of NULL.

  • has not been assigned a value yet.

  • is unset(). The

NULL type has only one value, which is the case-insensitive keyword NULL (you can write it as NULL or null).

Converting a variable to the null type will delete the variable and unset its value.

Type Conversion

PHP does not require (or support) explicit type definitions in variable definitions; the variable type is determined based on the context in which the variable is used. In other words, if a string value is assigned to the variable var, var becomes a string. If you assign an integer value to var, it becomes an integer.

An example of PHP’s automatic type conversion is the plus sign “+”. If any operand is a floating point number, all operands are treated as floating point numbers, and the result is also a floating point number. Otherwise the operands are interpreted as integers and the result is also an integer. Note that this does not change the types of the operands themselves; only how the operands are evaluated and the type of the expression itself is changed.

Type coercion in PHP is very much like in C: the variable to be converted is preceded by the target type enclosed in parentheses.

  • (int), (integer) - Convert to integer
  • (bool), (boolean) - Convert to Boolean
  • (float ), (double), (real) - Convert to float string(string)
  • (PHP 6)(array) - Convert to array(array)
  • (object) - Convert to object(object)
  • (unset) - Convert to NULL
  • (PHP 5)(binary) The conversion will prefix the result with 'b', new in PHP 5.2.1. The above introduces the data type PHP section 2 data type conversion, including data type content, I hope it will be helpful to friends who are interested in PHP tutorials.
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template