filter_has_var() checks whether an input variable exists in the selected external input source such as INPUT_GET or INPUT_POST.
if (filter_has_var(INPUT_GET, 'id')) {
echo 'id was supplied';
}
<?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";
}
?>
Output ( DEMO )No false $_GET['book_id']
What is GET and POST method of passing data ? bool filter_has_var(TYPE, variable_name);
The possible type of availability are
INPUT_POST,
INPUT_GET,
INPUT_COOKIE,
INPUT_SERVER,
INPUT_ENV
No false $_POST['book_id']Source code of above demo is here
<?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";
}
echo "</code></pre>";
?>
fillter_has_var is a better way than isset() function to to check the existence of a variable.filter_has_var() function in PHP?filter_has_var() determine if a specific variable exists in the given input?filter_has_var()?filter_has_var() to check if a specific variable exists in the $_GET superglobal array?filter_has_var() handle variables passed through different methods, such as GET, POST, and COOKIE?filter_has_var() be used to check if a variable exists in a custom request body or JSON payload?filter_has_var() return if the variable is found in the input?filter_has_var()? Why or why not?filter_has_var() to check if a variable exists and is of a specific data type, such as an integer or email?filter_has_var() be used to check if an array variable exists in the input?Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.