Home  >  Article  >  Backend Development  >  How to convert int to string in php

How to convert int to string in php

王林
王林Original
2020-08-28 13:36:575266browse

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)].

How to convert int to string in php

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:

<?php
$int_str= 123;
var_dump($int_str);
$str = strval(123);
var_dump($str);
?>

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!

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