How to use sprintf() Function In PHP
The sprintf() function writes a formatted string to a variable.
Syntax:
$str = sprintf("%d", $var_name);
Example:
<?php
$var_name = 2;
// Using sprintf to convert integer to string
$str = sprintf("%d", $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