PHP等同于.NET/Java的toString() [英] PHP equivalent of .NET/Java's toString()
本文介绍了PHP等同于.NET/Java的toString()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将PHP变量的值转换为字符串?
How do I convert the value of a PHP variable to string?
我正在寻找比连接空字符串更好的东西:
I was looking for something better than concatenating with an empty string:
$myText = $myVar . '';
类似于Java或.NET中的ToString()
方法.
Like the ToString()
method in Java or .NET.
推荐答案
您可以使用广播运营商:
$myText = (string)$myVar;
在 PHP手册的字符串部分,包括对布尔值和null的特殊处理.
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等同于.NET/Java的toString()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文