php functions that convert integers to strings include: 1. strval() function, which can obtain the string value of a variable, with the syntax format "strval (integer variable)"; 2. settype() function , this function can set the type of variable, the syntax format is "settype(integer variable,'string')".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php integer to String method
#1. Use the strval() function
The strval() function is used to obtain the string value of a variable. The syntax is as follows:
strval($var)
Parameter description:
$var: can be any scalar type, but cannot be an array or object.
Example:
<?php $int_str= 123; var_dump($int_str); $str = strval(123); var_dump($str); ?>
Output:
int(123) string(3) "123"
Explanation: The strval() function converts the data type, but will not affect the original variable type.
2. Use the settype() function
The settype() function is used to set the type of a variable. The syntax is as follows:
settype ( $var , $type )
Return value: TRUE is returned when the setting is successful, and FALSE is returned when the setting fails.
Example:
<?php $old=500; echo "原类型".gettype($old),'<hr>'; $current=gettype(settype($old,'string')); echo "现类型". gettype($current),'<hr>'; ?>
Output:
原类型integer 现类型string
Explanation: The settype() function will affect the type of the original variable.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is the php integer to string function?. For more information, please follow other related articles on the PHP Chinese website!