Q:

How to Convert an Integer to a String in PHP

0

How to Convert an Integer to a String in PHP

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the strval() Function

You can simply use type casting or the strval() function to convert an integer to a string in PHP.

 

Let's take a look at an example to understand how it basically works:

<?php
// Sample integer
$int = 10; 

// Casting integer to string
$var1 = (string) $int;  // $var1 is a string
var_dump($var1);

// Getting string value of a variable
$var2 = strval($int);  // $var2 is a string
var_dump($var2);
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP  and MySQL Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Delete PHP Array Element by Value Not Key... >>
<< How to Add Elements to an Empty Array in PHP...