Home  >  Article  >  Backend Development  >  How to convert characters to numbers in php

How to convert characters to numbers in php

王林
王林Original
2020-07-30 14:33:184223browse

php method to convert characters into numbers: You can use specific types of conversion functions, such as intval(), floatval(), strval(), etc. The intval() function is used to get the integer value of a variable. The floatval() function is used to obtain the floating point value of a variable.

How to convert characters to numbers in php

Function introduction:

(Recommended tutorial: php graphic tutorial)

intval( ) function is used to obtain the integer value of a variable.

intval() function returns the integer value of variable var by using the specified base conversion (default is decimal). intval() cannot be used with object, otherwise an E_NOTICE error will be generated and 1 will be returned.

floatval function is used to obtain the floating point value of a variable.

strval() function is used to get the string value of a variable.

The method is as follows:

Conversion method 1: Add the target type enclosed in parentheses before the variable to be converted, such as (int); (bool); (float); (string ); (array); (object)

How to convert characters to numbers in php

Conversion method two: use three specific types of conversion functions, intval(); floatval(); strval()

(Video tutorial recommendation: php video tutorial)

How to convert characters to numbers in php

Conversion method three: settype();

How to convert characters to numbers in php

The above is the detailed content of How to convert characters to numbers 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