strval

(PHP 4, PHP 5, PHP 7, PHP 8)

strval获取变量的字符串值

说明

strval(mixed $value): string

返回变量的字符串值。参见 string 文档获取更多关于转换为字符串的信息。

此函数对返回值不执行任何格式设置。如果需要将数值格式化字符串的方法,请参阅 sprintf()number_format()

参数

value

可以转换为 string 的变量。

value 可以是任何标量类型或者实现了 __toString() 方法的对象。不能在数组或者未实现 __toString() 方法的对象上使用 strval()

返回值

valuestring 值。

范例

示例 #1 使用 PHP 魔术方法 __toString()strval() 示例。

<?php
class StrValTest
{
public function
__toString()
{
return
__CLASS__;
}
}

// 打印“StrValTest”
echo strval(new StrValTest);
?>

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top