Home  >  Article  >  Backend Development  >  How to convert data types in PHP

How to convert data types in PHP

coldplay.xixi
coldplay.xixiOriginal
2020-10-08 17:19:033170browse

The method of data type conversion in PHP: first add the target type enclosed in parentheses before the variable to be converted; then use three specific types of conversion functions [intval(), floatval(), strval ()]; Finally, you can use the general type conversion function [settype(mixed var)].

How to convert data types in PHP

Data type conversion method in PHP:

1. Add parentheses before the variable to be converted Enclosed target type

2. Use three specific type conversion functions, intval(), floatval(), strval()

3. Use the general type conversion function settype(mixed var ,string type)

The first conversion method: (int) (bool) (float) (string) (array) (object)

The code is as follows:

 

The second conversion method: intval() floatval() strval()

The code is as follows:

   第三种转换方式:  settype();

The code is as follows:

 

If you want to know more about programming learning, please pay attention to the php training column!

The above is the detailed content of How to convert data types in PHP. For more information, please follow other related articles on the PHP Chinese website!

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