Difference between revisions of "PHP:Convert a String to a Number"

From Progzoo
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{topTenTips}}
 
{{topTenTips}}
 +
{{convertDataTypes}}
 
<question lang="php" className="Demo"><prog><![CDATA[
 
<question lang="php" className="Demo"><prog><![CDATA[
 
<?
 
<?
 
$s = "1234";
 
$s = "1234";
echo $s+1;
+
echo intval($s)+1;
 
?>
 
?>
 
]]>
 
]]>
Line 9: Line 10:
 
<p>
 
<p>
 
The language will automatically convert the string to an integer as required.
 
The language will automatically convert the string to an integer as required.
 +
 +
You can use the function '''intval'''
 
</p>
 
</p>
The value "1234" is a string, you need to treat it as a number -
+
<p class='imper'>The value "1234" is a string, you need to treat it as a number -
to add 1, giving 1235.
+
to add 1, giving 1235.</p>
 
</question>
 
</question>

Latest revision as of 18:40, 4 January 2010

The language will automatically convert the string to an integer as required. You can use the function intval

The value "1234" is a string, you need to treat it as a number - to add 1, giving 1235.

[Font] [Default] [Show] [Resize] [History] [Profile]