Home  >  Article  >  Backend Development  >  What is the php integer to string function?

What is the php integer to string function?

青灯夜游
青灯夜游Original
2021-03-26 18:28:312091browse

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')".

What is the php integer to string function?

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:

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 )

What is the php integer to string function?

Return value: TRUE is returned when the setting is successful, and FALSE is returned when the setting fails.

Example:

';
    $current=gettype(settype($old,'string'));
    echo "现类型". gettype($current),'
'; ?>

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!

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