Home  >  Article  >  Backend Development  >  How to convert characters to numeric type in php

How to convert characters to numeric type in php

王林
王林Original
2020-10-23 17:47:002546browse

php method to convert characters into numeric types: directly add the target type enclosed in parentheses before the variable to be converted, such as [(int)], [(float)]. You can also perform conversion by using the settype() function, such as [settype($num, "int")].

How to convert characters to numeric type in php

#1. The first conversion method: add the target type enclosed in parentheses before the variable to be converted, such as (int); (bool) ;(float);(string);(array);(object)

(Recommended tutorial: php video tutorial)

How to convert characters to numeric type in php

2. The second conversion method: use three specific types of conversion functions, intval(); floatval(); strval()

How to convert characters to numeric type in php

3. The third conversion Method: settype();

How to convert characters to numeric type in php

Related recommendations: php training

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