array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'en', ), 'this' => array ( 0 => 'function.strval.php', 1 => 'strval', ), 'up' => array ( 0 => 'ref.var.php', 1 => 'Variable handling Functions', ), 'prev' => array ( 0 => 'function.settype.php', 1 => 'settype', ), 'next' => array ( 0 => 'function.unserialize.php', 1 => 'unserialize', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/var/functions/strval.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
strval — Get string value of a variable
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().
value
The variable that is being converted to a string.
value
may be any scalar type, null,
or an object that implements the __toString()
method. You cannot use strval() on arrays or on
objects that do not implement the
__toString() method.
The string value of value
.
Example #1 strval() example using PHP magic __toString() method.
<?php
class StrValTest
{
public function __toString()
{
return __CLASS__;
}
}
// Prints 'StrValTest'
echo strval(new StrValTest);
?>