Checking how filter_var() works when passed various inputs and using the FILTER_VALIDATE_INT filter.

The code is set up as follows:
$filtered = filter_var($var, FILTER_VALIDATE_INT);
var_dump($filtered);

with the value of $var changing, as shown.

$var = 10;
int(10)

$var = '10';
int(10)

$var = '10.5';
bool(false)


Checking how filter_var() works with the FILTER_VALIDATE_FLOAT filter.

The code is set up as follows:
$filtered = filter_var($var, FILTER_VALIDATE_FLOAT);
var_dump($filtered);

with the value of $var changing, as shown.

$var = '10.5';
float(10.5)

$var = 10;
float(10)


Checking how filter_var() works with filter_id().

The code is set up as follows:
$filtered = filter_var($var, filter_id('float'));
var_dump($filtered);

$var = '10';
float(10)

To use the previous example in conjunction with a form, filter_var() needs to be passed the following:
$filtered = filter_var(INPUT_POST, 'var', FILTER_VALIDATE_INT);