开发者

why people are defining data type in php?

开发者 https://www.devze.com 2023-01-16 09:15 出处:网络
Hi friends why people are defining data type in php as below, $id 开发者_StackOverflow= (int) $_GET[\'id\'];

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

精彩评论

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