an alternative if you want to check if it's a valid integer:
<?php
if(false!==filter_var($v, FILTER_VALIDATE_INT)){
// it's a valid int!
$v=(int)$v;
}else{
// it's not a valid int
}
?>
or if you want to check that it's a positive integer (>= 0):
<?php
if(false!==filter_var($v, FILTER_VALIDATE_INT, ["options"=>["min_range"=>0]])){
// it's a valid positive integer!
$v = (int)$v;
}else{
// it's not a valid positive integer
}
?>