strval() to get string from a variable
From any type of data ( variable ) we can get string output. This can be used to convert any numeric data to string.
echo strval(34)."<br>"; //34
echo strval(12.34)."<br>"; // 12.34
echo strval(12.340)."<br>"; // 12.34
echo strval(.34)."<br>"; // 0.34
echo strval(0.34)."<br>"; // 0.34
echo strval(-0.34)."<br>"; // -0.34
echo strval('plus2net')."<br>";// plus2net
The return value is string.
Application using strval()
Find the sum of every 2nd digit of any integer.
$my_num=strval(12345678);
$sum=0;
for($i=0; $i<strlen($my_num); $i++){
if(($i % 2) ==0){
$sum=$sum + $my_num[$i];
}
}
print($sum)
Output is 16
←Declaring variables Cookies to store Infomation →
Getting Type of Variable→ var_dump()→ empty()→
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com
Click for more tutorial on PHP Variables and Functions |
|