filter_var(): Checks a variable with a specified filter
$book_id='abc'; // change this to integer to check
if(filter_var($book_id,257)){ // Filter id 257 is for validating integers
echo "Yes true book_id validation passed";
}else{
echo "No false book_id validation failed";
}
output
No false book_id validation failed
We can check a variable by using a particular type of filter by using filter_var() function. This function takes the variable and the ID or name of the filter as input and checks the variable. It returns True of False based on the checking output. Here is the syntax.