Home > Backend Development > PHP Tutorial > PHP data type automatic conversion

PHP data type automatic conversion

WBOY
Release: 2016-08-08 09:20:31
Original
1738 people have browsed it

1: Overview---php is a weakly typed language, which can automatically convert data types according to changes in the running environment

1.1 Principles of conversion to Boolean types

 The following values ​​will be converted into Boolean types false:

  A. Boolean type false;

  B. Empty string ''

  C. Positive number 0 or floating point number 0.0 or string '0' (excluding string '0.0')

  D .Array without members----array()

  E.null

Except for this, all other values ​​are converted to true.

1.2 Principles of conversion to numerical type

A. If the string is a legal number If the string does not contain ./e/E and does not exceed the storage range of the integer type, it will be converted to an integer type; otherwise, it will be converted to a floating point type;

 B. If the numeric string starts with an illegal character, then converted to 0;

C. Boolean true is converted to integer 1, false is converted to integer 0;

D. null is converted to 0

E. Floating point numbers are rounded down when converted to integers

1.3 Conversion The principle of converting into a string

A. The value is converted into a string, which is the value itself; String'';

  D. Convert the array to Array

  E. The resource will be converted to Resource id #number

The above introduces the automatic conversion of data types in PHP, including aspects of it. 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