php / 8.1.5 / function.strval.html /

strval

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

strvalGet string value of a variable

Description

strval(mixed $value): string

Get the string value of a variable. See the documentation on string for more information on converting to string.

This function performs no formatting on the returned value. If you are looking for a way to format a numeric value as a string, please see sprintf() or number_format().

Parameters

value

The variable that is being converted to a string.

value may be any scalar type or an object that implements the __toString() method. You cannot use strval() on arrays or on objects that do not implement the __toString() method.

Return Values

The string value of value.

Examples

Example #1 strval() example using PHP magic __toString() method.

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

// Prints 'StrValTest'
echo strval(new StrValTest);
?>

See Also

© 1997–2021 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.
https://www.php.net/manual/en/function.strval.php