Home > Backend Development > PHP Tutorial > PHP Section 2 Data Type Conversion_PHP Tutorial

PHP Section 2 Data Type Conversion_PHP Tutorial

WBOY
Release: 2016-07-21 15:19:33
Original
846 people have browsed it

A variable is considered NULL when:

  • is assigned the value 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 casting in PHP is very much like in C: the variable to be converted is preceded by the target type enclosed in parentheses.

  • (int), (integer) - converted to integer
  • (bool), (boolean) - Convert to 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(array)
  • (object) - Convert to object (object)
  • (unset) - Convert to NULL (PHP 5)

(binary) conversion will prefix the result with 'b', new in PHP 5.2.1.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325298.htmlTechArticleA variable is considered NULL in the following situations: Is assigned a value of NULL. Has not been assigned a value yet. Been unset() . The NULL type has only one value, which is the case-insensitive keyword NULL (...
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