Home >Backend Development >PHP Problem >How to convert numbers to characters in php?
How to convert numbers to characters in php: 1. Use forced data type conversion to convert the number type to a string type; 2. Use the strval() function to convert the number to a string and return the string type value.
Method 1: Use forced data type conversion
(string): Convert to string
Example:
<?php header("Content-Type: text/html; charset=utf-8"); $num1=3.14; $num2=(string)$num1; var_dump($num1); //输出float 3.14 var_dump($num2); //输出string '3.14' (length=4) ?>
Method 2: Use the strval() function
strval() — Get the string value of the variable.
Example:
<?php header("Content-Type: text/html; charset=utf-8"); $num1=3.14; $num2=strval($num1); var_dump($num1); var_dump($num2); ?>
Recommended learning:php tutorial
The above is the detailed content of How to convert numbers to characters in php?. For more information, please follow other related articles on the PHP Chinese website!