How to use Explicit Casting. In PHP
Note: 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.
Syntax:
$str = (string)$var_name
Example:
<?php
$var_name = 2;
//Typecasting Integer into string
$str = (string)$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