The strval() function is an inbuilt function in PHP and is used to convert any scalar value (string, integer, or double) to a string. We cannot use strval() on arrays or on object, if applied then this function only returns the type name of the value being converted.
Syntax:
strval( $variable )
Parameter: This function accepts a single parameter $variable. This parameter represents the value which we want to convert to string
Return value: This function returns a string. This string is generated by typecasting the value of the variable passed to it as a parameter.
Below programs illustrate the strval() function.
Program 1:
<?php
$var_name = 32.360;
echo strval ( $var_name );
?>
|
Output:
32.36
Program 2:
<?php
class geeksforgeeks
{
public function __toString()
{
return __CLASS__ ;
}
}
echo strval ( new geeksforgeeks);
?>
|
Output:
geeksforgeeks
Program 3:
<?php
$arr = array (1,2,3,4,5);
echo strval ( $arr );
?>
|
Reference:
http://php.net/manual/en/function.strval.php
PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.
Last Updated :
31 Jul, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...