How to use strval() function. In PHP
Note: 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 )
Return value: This function returns a string. This string is generated by typecasting the value of the variable passed to it as a parameter.
Example:
<?php
$var_name = 2;
// converts integer into string
$str = strval($var_name);
// prints the value of above variable as a string
echo "Welcome $str w3wiki";
?>
Output
Welcome 2 w3wiki
How to convert an Integer Into a String in PHP ?
The PHP strval() function is used to convert an Integer Into a String in PHP. There are many other methods to convert an integer into a string.
In this article, we will learn many methods.
Methods:
Table of Content
- Using strval() function.
- Using Inline variable parsing.
- Using Explicit Casting.
- Using sprintf() Function
- Using concatenation with an Empty String