The strval Function
The strval
function returns the string representation of the passed value.
It accepts any scalar value or object as a parameter,
that can be converted to a string.
Syntax
strval(mixed $value): string
Example
Convert a number to a string:
<?php
$num = 123;
$res = strval($num);
var_dump($res);
?>
Code execution result:
'123'
Example
Convert a boolean value to a string:
<?php
$bool = true;
$res = strval($bool);
var_dump($res);
?>
Code execution result:
'1'
Example
Let's try to convert an array to a string:
<?php
$arr = [1, 2, 3];
$res = strval($arr);
var_dump($res);
?>
Code execution result:
'Array'