What is the php integer to string function?

青灯夜游
Release: 2023-03-09 07:18:01
Original
2179 people have browsed it

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)
Copy after login

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);
?>
Copy after login

Output:

int(123)
string(3) "123"
Copy after login

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 )
Copy after login

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:

<?php
  $old=500;
    echo "原类型".gettype($old),&#39;<hr>&#39;;
    $current=gettype(settype($old,&#39;string&#39;));
    echo "现类型". gettype($current),&#39;<hr>&#39;;
?>
Copy after login

Output:

原类型integer
现类型string
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!