I have realized that PHP can treat string variables as numbers (as long as int or float values are stored in the string variables), for example:
<?php
// Declaring two int numbers and one float number as string variables
$i = "10";
$j = "3";
$f = "5.2";
// Adding an int number and a float number represented as string variables
$result = $i + $f;
echo $result . "<br />"; // will print "15.2"
// Comparing two int numbers represented as string variables
if ($i > $j)
{
echo "i is bigger than j"; // this statement will be executed
}
else
{
echo "i is not bigger than j";
}
?>
My question is, why do we have int and float data types in PHP, why not just store int and float numbers in string variables like I did in the above code?
intorfloatvariables (for example:$i = 10; $f = 2.4;)? I mean in the Bash shell for example, I think anintvariable is stored as astring, but you can't explicitly create anintvariable I think.