Home > Backend Development > PHP Problem > How to convert variable into string in php

How to convert variable into string in php

王林
Release: 2023-03-05 17:46:02
Original
4704 people have browsed it

php method to convert variables into strings: use the built-in function strval(), the syntax is "strval (var)", where var can be any scalar type; the strval() function can get the string of the variable value and returned, but cannot be used for arrays or objects.

How to convert variable into string in php

There is a built-in function strval() in php, which is used to get the string value of a variable and return it.

(Recommended tutorial: php video tutorial)

Function syntax:

string strval ( mixed $var )
Copy after login

Note: var can be any scalar type. You cannot use strval() with arrays or objects.

Code example:

<?php
$foo = strval(123);
var_dump($foo);
?>
Copy after login

(Related recommendations: php training)

Output result:

string(3) "123"
Copy after login

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