Sarfraz Sarfraz - 3 months ago 9
PHP Question

Is there any particular difference between intval and casting to int - `(int) X`?

Is there any particular difference between intval and (int)?

Example:

$product_id = intval($_GET['pid']);
$product_id = (int) $_GET['pid'];


Is there any particular difference between above two lines of code?

Answer

intval() can be passed a base from which to convert. (int) cannot.

int intval( mixed $var  [, int $base = 10  ] )