Home > Article > Backend Development > How to convert characters to numbers in php
The way to convert characters into numbers in php is: you can use the intval() function. This function returns the integer value of the variable by using the specified base conversion. The specific usage method is: [echo intval('42');], in which the integer 42 will be output.
Related function introduction:
intval() function is used to obtain the integer value of a variable.
(Recommended tutorial: php tutorial)
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.
Function syntax:
int intval ( mixed $var [, int $base = 10 ] )
Parameter description:
$var: the quantity value to be converted into integer;
$base: The base used for conversion. If base is 0, the base used is determined by detecting the format of var;
If the string includes the prefix of "0x" (or "0X"), use hexadecimal (hex);
If the string starts with "0", use octal (octal);
Return value:
Returns the integer value of var on success, and returns 0 on failure. An empty array returns 0, a non-empty array returns 1.
Code:
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!