filter_has_var(): Check if variable is specified type
<?php
$book_id=100; // Direct variable , not through GET
if(filter_has_var(INPUT_GET,'book_id')){
echo "Yes true $_GET[book_id]";
}else{
echo "No false $_GET[book_id]";
}
?>
What is GET and POST method of passing data ? → filter_has_var function checks the variable of specified type is available or not. The same result can be achieved by using isset() function also but the advantage of filter_has_var is it checks the specified type of input ( source ) is available or not. If we expect the variable to be available by POST method and not by GET method for form posting then the same can be checked by using filter_has_var function in PHP.
<?Php
echo "<pre><code>";
$book_id=100; // Direct variable , not through GET
if(filter_has_var(INPUT_POST,'book_id')){
echo "Yes true $_POST[book_id]";
}else{
echo "No false $_POST[book_id]";
}
echo "</code></pre>";
?>
fillter_has_var is a better way than isset() function to to check the existence of a variable.
Questions
What is the purpose of the filter_has_var() function in PHP?
How does filter_has_var() determine if a specific variable exists in the given input?
What are the possible types of filters that can be used with filter_has_var()?
How can you use filter_has_var() to check if a specific variable exists in the $_GET superglobal array?
How does filter_has_var() handle variables passed through different methods, such as GET, POST, and COOKIE?
Can filter_has_var() be used to check if a variable exists in a custom request body or JSON payload?
What value does filter_has_var() return if the variable is found in the input?
Is it necessary to sanitize or validate the variable after using filter_has_var()? Why or why not?
How can you use filter_has_var() to check if a variable exists and is of a specific data type, such as an integer or email?
Can filter_has_var() be used to check if an array variable exists in the input?