PHP代码
$id=intval($_GET['id']);
intval
(PHP4,PHP5)
intval—Gettheintegervalueofavariable
Description
intintval(mixed$var[,int$base=10])
Returnstheintegervalueofvar,usingthespecifiedbasefortheconversion(thedefaultisbase10).
Parameters
var
Thescalarvaluebeingconvertedtoaninteger
base
Thebasefortheconversion(defaultisbase10)
ReturnValues
Theintegervalueofvaronsuccess,or0onfailure.Emptyarraysandobjectsreturn0,non-emptyarraysandobjectsreturn1.
Themaximumvaluedependsonthesystem.32bitsystemshaveamaximumsignedintegerrangeof-2147483648to2147483647.Soforexampleonsuchasystem,intval('1000000000000')willreturn2147483647.Themaximumsignedintegervaluefor64bitsystemsis9223372036854775807.
Stringswillmostlikelyreturn0althoughthisdependsontheleftmostcharactersofthestring.Thecommonrulesofintegercastingapply.
Examples
复制代码代码如下:
echointval(42);//42
echointval(4.2);//4
echointval('42');//42
echointval('+42');//42
echointval('-42');//-42
echointval(042);//34
echointval('042');//42
echointval(1e10);//1410065408
echointval('1e10');//1
echointval(0x1A);//26
echointval(42000000);//42000000
echointval(420000000000000000000);//0
echointval('420000000000000000000');//2147483647
echointval(42,8);//42
echointval('42',8);//34
?>
您可能感兴趣的文章:php中的四舍五入函数代码(floor函数、ceil函数、round与intval)PHP取整函数:ceil,floor,round,intval的区别详细解析解析PHP中intval()等int转换时的意外异常情况PHP中将字符串转化为整数(int)intval()printf()性能测试php数据入库前清理注意phpintval与mysql的int取值范围不同phpintval的测试代码发现问题php下intval()和(int)转换使用与区别phpintval函数用法总结