Home>Article>Backend Development> How to convert int to string in php
How to convert int to string in php: You can use the type conversion function strval() to achieve this. The strval() function can obtain the string value of a variable. The function syntax is: [strval($var)], where $val can be any scalar type. For example: [strval(123)].
There are three conversion methods for PHP data types:
(Learning video recommendation:php video tutorial)
Add the target type enclosed in parentheses before the variable to be converted;
Use three specific types of conversion functions, intval(), floatval(), strval();
Use the general type conversion function settype(mixed var, string type);
Here we introduce the second method, using the strval() function for conversion.
strval() function is used to get the string value of a variable.
Grammar:
string strval ( mixed $var )
(Related recommendations:php training)
Code example:
Running results:
int(123) string(3) "123"
The above is the detailed content of How to convert int to string in php. For more information, please follow other related articles on the PHP Chinese website!