Home  >  Article  >  Backend Development  >  How to convert integer to string type in php?

How to convert integer to string type in php?

青灯夜游
青灯夜游Original
2020-10-07 10:51:255487browse

Methods to convert integers to string types in php: 1. Use forced type conversion and add the target type "(string)" enclosed in parentheses before the integer variable to be converted; 2 , use the strval() function; 3. Use the "settype (integer variable, "string")" method.

How to convert integer to string type in php?

Recommended: "PHP Video Tutorial"

Method 1: Forced type conversion---in The variable to be converted is preceded by the target type "(string)" enclosed in parentheses

Example:

Output result:

How to convert integer to string type in php?

Method 2: Use strval() function

strval(): used to get the string value of a variable.

Example

Output:

string '545248' (length=6)

Method 3: Use settype(mixed var,string type)

The settype() function is used to set the type of a variable.

Syntax

bool settype ( mixed &$var , string $type )

Parameter description:

$var: The variable to be converted.

$type: Possible values ​​for type are.

  • "boolean" (or "bool" since PHP 4.2.0)

  • "integer" (or "int" , starting from PHP 4.2.0)

  • "float" (only available after PHP 4.2.0, "double" used in older versions is now deprecated)

  • "string"

  • "array"

  • "object"

  • "null" (since PHP 4.2.0)

Example:

Output:

boolean true
string '545248' (length=6)

The above is the detailed content of How to convert integer to string type in php?. 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