Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How do I convert the value of a PHP variable to string?

(如何将PHP变量的值转换为字符串?)

I was looking for something better than concatenating with an empty string:

(我在寻找比连接空字符串更好的东西:)

$myText = $myVar . '';

Like the ToString() method in Java or .NET.

(类似于Java或.NET中的ToString()方法。)

  ask by Antoine Aubry translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
326 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use the casting operators :

(您可以使用强制转换运算符 :)

$myText = (string)$myVar;

There are more details for string casting and conversion in the Strings section of the PHP manual, including special handling for booleans and nulls.

(PHP手册的“ 字符串”部分提供了有关字符串转换和转换的更多详细信息,包括对布尔值和null的特殊处理。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...