Page 1 of 1
How can I convert a string to int?
Posted: Thu May 25, 2006 12:22 am
by theoretical_dreamer
for example:
Code: Select all
<?
$var1=12;
$var2="12"; //How can I convert this to int?
if ($var1==$var2)
{
print "It works";
}
?>
Re: How can I convert a string to int?
Posted: Thu May 25, 2006 12:30 am
by Christopher
Code: Select all
<?
$var1=12;
$var2=(int)"12"; //by casting to new type
$var2=intval("12"); //or using a conversion function
if ($var1==$var2)
{
print "It works";
}
?>
Posted: Thu May 25, 2006 3:06 am
by onion2k
For the record, the code in the first post works fine for me. PHP's loose typing means INT==STRING is fine .. it's only when you do INT===STRING it'd start to fail.