开发者

why people are defining data type in php?

Hi friends why people are defining data type in php as below,

$id 开发者_StackOverflow= (int) $_GET['id']; 


To make sure the variable really contains a valid number. For example, empty string will be converted to 0, 'abc' will be converted to 0, etc.


This assigns the value of the URL parameter "id" (converted to an integer) to the variable $id. The parameters in the URL are of course strings, therefore if you pass an integer this way you first should cast it to the int datatype.


Because that way you know what you are manipulating so there is no surprise.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜