➤ Using
strval()
function.
• 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.
$number = 10;
// converts integer into string
$str = strval($number);
echo gettype($str); // outputs: string
➤ Using inline variable parsing.
• When you use Integer inside a string, then the Integer
is first converted into a string and then prints as a string.
$integer = 10;
$str = "$integer";
echo gettype($str); // outputs: string
➤ Using explicit Casting.
• Explicit Casting is the explicit conversion of data type because the
user explicitly defines the data type in which he wants to cast.
We will convert Integer into String.
$num = 5;
$str = (string)$num; // or String
echo gettype($str); // outputs: string