You can use the default option to achieve this. If the value is not set, the default value will be assigned, for example, as follows
$options = array( 'options' => array('default'=> 0) ); $valid = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT, $options);
filter_input () cannot be read from _POST / _GET / _COOKIE / _SERVER / _ENV
$opened_staff['id'] = 0; if($valid){ $opened_staff['id'] = $_GET['id']; }
You can use some class to achieve this. [NOTE: - this is just an example]
class RequestFilter{ public static function get_filter_int($id){ $options = array( 'options' => array('default'=> 0) ); $valid = filter_input(INPUT_GET, $id, FILTER_VALIDATE_INT, $options); if($valid){ return $_GET[$id];
here it will return the value or the default value, here it is zero.
source share